【问题标题】:jQuery Uploadify HTTP error (HTTP error: 302)jQuery Uploadify HTTP 错误(HTTP 错误:302)
【发布时间】:2011-11-21 20:31:02
【问题描述】:

Uploadify 不断给我一个“HTTP 错误”并且它开始变得很烦人。

这是我调用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 代码在我使用表单时有效:

发送这个文件:

【问题讨论】:

    标签: php jquery forms upload uploadify


    【解决方案1】:

    您在文件末尾缺少} 以关闭if (!empty($_FILES)) {

    也许使用不同的 IDE?

    【讨论】:

    • 这只是代码的一部分。通过常规表单发布时,PHP 端可以工作。
    • 嗯,好的。我将您的代码复制到一个文件中,但没有收到错误,但我没有发送文件。也许问题不在于这部分代码?您可以逐块删除代码以查找错误。
    • 我设法解决了这个问题。结果发现代码有问题,但会话也有问题。我暂时禁用了上传脚本上的会话,但我仍然需要为此找到永久解决方案。
    猜你喜欢
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    相关资源
    最近更新 更多