由于uploadify屬于flash上傳,意味著當(dāng)上傳的時(shí)候會(huì)新建一個(gè)新的session會(huì)話(huà),php后臺(tái)處理的時(shí)候會(huì)接收不到當(dāng)前瀏覽器的session會(huì)話(huà)參數(shù). 如果上傳文件后臺(tái)地址做了基于服務(wù)器session值作為登錄或者其他條件判斷的話(huà),將會(huì)失效.這也是 uploadify 一個(gè)bug,官方給出了php的解決方法.
In Uploadify, the Flash file is what communicates with the backend script.? Because of a bug in Flash, the session cookie is not picked up by the Flash file.? To circumvent this, you will need to pass the session data via the formDataoption.? To do this in PHP, use the following code when initializing Uploadify on the front-end page:
前臺(tái)使用uploadify的地方加入一下代碼
$('#file_upload).uploadify({
// Your normal options here
formData : { '<?php echo session_name();?>' : '<?php echo session_id();?>' }
});
后臺(tái)方面,即加入判斷如果存在了session_name則 以u(píng)ploadify傳入的session作為新的依據(jù)
$session_name = session_name();
if (!isset($_POST[$session_name])){
//exit;
} else {
session_destroy();
session_id($_POST[$session_name]);
@session_start();
}
如果使用的是thinkphp框架的話(huà),前端不變,后端如果使用的是tp中的session作為判決依據(jù)則可以這么寫(xiě)
$session_name = session_name();
if (!isset($_POST[$session_name])){
//exit;
} else {
session('[pause]');? ? ? ? ? ? ? ? //tp默認(rèn)已經(jīng)開(kāi)啟,先暫停
session_id($_POST[$session_name]);? //這個(gè)要在session_start()之前
session('[start]');? ? ? ? ? ? ? ? //再開(kāi)啟
}