使用fireify与fireify时会话不起作用

时间:2012-08-28 04:46:25

标签: php javascript jquery mysql uploadify

我的uploadify脚本适用于包括IE在内的所有浏览器。但是没有在firefox中工作。我有三个文件。 1>包含uploadify脚本和变量 2>是newuploadify.php,它启动会话并为会话变量提供一些值。 3>是根据会话在数据库中插入数据。

除了Chrome(不是Chrome)和Firefox之外,它在所有浏览器中都能很好地工作。

不知何故,会话没有从Firefox的第二个文件传递到第三个文件。

我的脚本

1> `

<?php if (!isset($_SESSION)) {
session_start();
}
?>
<html>
<head>
<style>
<style type="text/css">
    .uploadify-button {
        background-color: transparent;
        border: none;
        padding: 0;
    }
    .uploadify:hover .uploadify-button {
        background-color: transparent;
    }
</style>
</style>
<script type="text/javascript" src="uploadify/jquery.uploadify-3.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="uploadify/uploadify.css" />
<script>
 var $j = jQuery.noConflict();
$j(document).ready(function(){
  $j("#photocancelbtn").hide();
  $j("#photouploadstartbtn").hide();
   $j("#filein").hide();
  $j("#filein").fadeIn(8000);
$j(function() {
    $j('#file_upload').uploadify({
        auto : false,
            'swf'      : 'uploadify/uploadify.swf',
            'uploader' : 'newuploadify.php',
             // Put your options here

        'queueSizeLimit' : 1,
        'checkExisting' : '/uploadify/check-exists.php',
        'multi'    : false,
        'buttonText' : 'Add Photo',
        'fileTypeDesc' : 'Image Files',
            'fileTypeExts' : '*.gif; *.jpg; *.png; *.JPG',
        'fileSizeLimit' : '5MB',
        'onClearQueue' : function(queueItemCount) {
               $j("#photocancelbtn").hide();
               $j("#photouploadstartbtn").hide();
        },
        'onSelect' : function(file) {
              $j("#photocancelbtn").show();
              $j("#photouploadstartbtn").show();
        },

        'onUploadSuccess' : function(file, data, response) {
                $j("#photocancelbtn").hide();
               $j("#photouploadstartbtn").hide();

               changeBtnText();
    }


    }); /* closing uploadify line*/

}); /* closing funciton line*/
}); /*closing document ready function*/
function changeBtnText() {
    $j('#file_upload').uploadify('settings','buttonText','Change Photo');
}
function restoreBtnText() {
    $j('#file_upload').uploadify('settings','buttonText','Add Photo');
}   

</script>
</head>
<body>
<table>
<tr>
<td id="filein">
<input type="file" name="file_upload" id="file_upload" />
</td>
<td id="btns">
<a id="photouploadstartbtn" href="javascript:$j('#file_upload').uploadify('upload')">Start Upload</a><br>
<a id="photocancelbtn" href="javascript:$j('#file_upload').uploadify('cancel','*');">Remove photo</a>
</td>
</tr>
</table>
</body>
</html>

`

还尝试在上面的代码中通过scriptData传递数据,但结果仍然相同。

2 - ;

`

<?php if (!isset($_SESSION)) {
session_start();
}
require('connection.php');
$targetFolder = '/images/'; // Relative to the root
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    $randomid=uniqid();
    $targetFile = rtrim($targetPath,'/') . '/'.$randomid.$_FILES['Filedata']['name'];

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png','JPG','PNG'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
    $fp     = fopen($tempFile, 'r');
    $data = fread($fp, filesize($tempFile));
    $data = addslashes($data);
    fclose($fp);



move_uploaded_file($tempFile,$targetFile);
$_SESSION['photopath'] = $randomid.$_FILES['Filedata']['name']; //Just storing the file name for the path.
$_SESSION['photocheck']='Y';
/*The above sessions are setting but are not being passed to the third file.
error_log($_SESSION['photopath']);
error_log($_SESSION['photocheck']);
error_log(session_id());

    } else {
        echo 'Invalid file type.';

    }
}
?>

`

3&GT;

`

#Getting if photo is added.
                if(isset($_SESSION['photocheck'])){
                    $photocheck=$_SESSION['photocheck'];
                    error_log('Photocheck=');
                    error_log($photocheck);
                    unset($_SESSION['photocheck']);
                }
                if(isset($_SESSION['photopath'])){
                //$photo=$_SESSION['photo'];#Encoding string as image. For using mysqli no need to do this step.just bind param as string.
                $photopath=$_SESSION['photopath'];
                error_log('Photopath=');
                    error_log($photopath);
                unset($_SESSION['photopath']);
                }

                #Inserting 
                if($photocheck=='Y'){
                error_log('Entered into insert q');

                }
                else{
                error_log('Did not enter !!');
                }

`

我正在使用firefox时没有输入,使用其他浏览器时输入插入q。请帮帮我。

2 个答案:

答案 0 :(得分:0)

您不必这样做:

<?php if (!isset($_SESSION)) {
         session_start();
      }
?>

PHP知道不要启动另一个会话,所以你可以让它原样

<?php
     session_start();
?>

另外请确保require('connection.php');中没有任何输出如果它只是PHP脚本,你可以省略最后?>个php块,只是为了确保你没有有任何额外的空间。

答案 1 :(得分:0)

if(@$_REQUEST['SESSION_ID'] && ($session_id=$_REQUEST['SESSION_ID']) !=session_id()){
    session_destroy();
    session_id($session_id);
    @session_start();    
}

正确答案