2011-09-21 108 views
0

Uploadify不斷給我一個「HTTP錯誤」,並開始變得非常討厭。jQuery Uploadify HTTP錯誤(HTTP錯誤:302)

這是我如何調用uploadify:

$(document).ready(function() { 
    $('#upload_image').uploadify({ 
    'uploader' : '/templates/v2/uploadify/uploadify.swf', 
    'script' : '/userimages.php', 
    'cancelImg' : '/templates/v2/images/cancel.png', 
    'folder' : '/images/uploads/1', 
    'auto'  : true, 
    'fileExt' : '*.jpg;*.gif;*.png', 
    'fileDesc' : 'Image Files (.JPG, .GIF, .PNG)', 
    'removeCompleted' : false, 
    'buttonText' : 'Upload Image' 
    }); 
}); 

<input id="upload_image" name="userfiles" type="file" /> 

PHP代碼:

if (!empty($_FILES)) { 
$tempFile = $_FILES['userfile']['tmp_name']; 
$targetPath = '/home/emailsms/app/images/uploads/' . $_SESSION['uid'] . '/'; 
$targetFile = $targetPath . $_FILES['userfile']['name']; 
move_uploaded_file($tempFile, $targetFile); 
switch ($_FILES['userfile']['error']) { 
    case 0: 
     $msg = ""; // comment this out if you don't want a message to appear on success. 
     break; 
    case 1: 
     $msg = "The file is bigger than this PHP installation allows"; 
     break; 
    case 2: 
     $msg = "The file is bigger than this form allows"; 
     break; 
    case 3: 
     $msg = "Only part of the file was uploaded"; 
     break; 
    case 4: 
     $msg = "No file was uploaded"; 
     break; 
    case 6: 
     $msg = "Missing a temporary folder"; 
     break; 
    case 7: 
     $msg = "Failed to write file to disk"; 
     break; 
    case 8: 
     $msg = "File upload stopped by extension"; 
     break; 
    default: 
     $msg = "unknown error " . $_FILES['userfile']['error']; 
     break; 
} 

if ($msg) { 
    $stringData = "Error: " . $_FILES['userfile']['error'] . " Error Info: " . $msg; 
} else { 
    $stringData = "1"; 
} 

echo $stringData; 

當我使用一種形式的PHP代碼工作:

<表單的enctype =「多/形式 - data「action =」/ userimages「method =」POST「> 發送文件:< input name =」userfile「type =」file「/> < input t YPE = 「提交」 值= 「發送文件」/> </form>中

回答

1

你缺少一個}在文件的結尾關閉if (!empty($_FILES)) {

可能使用不同的IDE?

+0

這只是部分的代碼。通過常規表單發佈時,PHP端可以正常工作。 –

+0

好的。我將您的代碼複製到一個文件中,但沒有收到錯誤,但我沒有發送文件。也許問題不在代碼的這一部分?您可以逐塊移除代碼以查找錯誤。 – PiTheNumber

+0

我設法解決這個問題。結果發現代碼存在問題,但會話也存在問題。我暫時禁用了上傳腳本的會話,但我仍然需要爲此找到永久的解決方案。 –

0

儘量把這個在.htaccess

SecFilterEngine Off 
SecFilterScanPOST Off 

試試這個線程:Uploadify: show error message from HTTP response

+0

我沒有在服務器上啓用mod_security,因爲這是將要在服務器上運行的唯一網站。 –