jQuery Uploadify HTTP错误(HTTP错误:302)

问题描述:

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>中

你缺少一个}在文件的结尾关闭if (!empty($_FILES)) {

可能使用不同的IDE?

+0

这只是部分的代码。通过常规表单发布时,PHP端可以正常工作。 –

+0

好的。我将您的代码复制到一个文件中,但没有收到错误,但我没有发送文件。也许问题不在代码的这一部分?您可以逐块移除代码以查找错误。 – PiTheNumber

+0

我设法解决这个问题。结果发现代码存在问题,但会话也存在问题。我暂时禁用了上传脚本的会话,但我仍然需要为此找到永久的解决方案。 –

尽量把这个在.htaccess

SecFilterEngine Off 
SecFilterScanPOST Off 

试试这个线程:Uploadify: show error message from HTTP response

+0

我没有在服务器上启用mod_security,因为这是将要在服务器上运行的唯一网站。 –