0

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

这在除 chromium(不是 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>

`

#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 时没有输入,在使用其他浏览器时输入了 insert q。请帮我 。

4

2 回答 2

0

您不必这样做:

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

PHP 知道不要开始另一个会话,所以你可以让它保持原样

<?php
     session_start();
?>

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

于 2012-08-28T05:17:09.917 回答
0
if(@$_REQUEST['SESSION_ID'] && ($session_id=$_REQUEST['SESSION_ID']) !=session_id()){
    session_destroy();
    session_id($session_id);
    @session_start();    
}

正确答案

于 2013-05-28T02:12:34.950 回答