2012-08-28 51 views
0

我的uploadify腳本可以在所有瀏覽器(包括IE)中使用。但不能在Firefox中工作。我有三個文件。 1>包含uploadify腳本和變量 2> newuploadify.php啓動會話併爲會話變量提供一些值。 3>是根據會話在數據庫中插入數據。通過firefox使用uploadify時會話不起作用

這在除鉻(不是鉻)和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時沒有進入,並在使用其他瀏覽器時輸入插入q。請幫幫我 。

回答

0

你不必這樣做:

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

PHP知道不能啓動另一個會話,這樣就可以讓因爲它是

<?php 
    session_start(); 
?> 

另外,還要確保你沒有任何輸出require('connection.php');如果只有PHP腳本,你可以省略php塊的最後?>,只是爲了確保你沒有任何額外的空間。

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

正確的答案