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

发布于 2024-12-05 20:18:50 字数 2070 浏览 1 评论 0原文

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 代码起作用:

发送此文件: <输入类型=“提交”值=“发送文件”/>

Uploadify keeps giving me a "HTTP error" and its starting to get pretty annoying.

Here is how I invoke 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 Code:

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;

The PHP code works when I use a form:

<form enctype="multipart/form-data" action="/userimages" method="POST">
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2024-12-12 20:18:50

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

也许使用不同的 IDE?

You are missing a } at the end of the file to close if (!empty($_FILES)) {

Maybe use a different IDE?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文