Uploadify:显示来自HTTP响应的错误消息

hop*_*pla 18 uploadify

如果服务器在使用Uploadify上传文件时返回错误(HTTP响应代码!= 200),则上传的文件将显示红色背景,并显示如下消息:

file.jpg (52.78KB) - HTTP Error
Run Code Online (Sandbox Code Playgroud)

表示存在HTTP错误.但这对用户来说并不是很有用.如何让它显示更详细的错误消息?喜欢:'不是有效图像'或'配额满'?

我在考虑在HTTP响应体中传递这些消息,但是Uploadify没有接收它们.有没有已知的方法将错误消息传递回Uploadify?

Gab*_*oli 9

看看uploadify论坛中关于如何处理错误的这两篇文章

onError显示正在发生的事情上传脚本错误报告

那里有很多有用的信息..

更新

以下似乎为我做了诀窍..

'onComplete': function(a, b, c, d, e){
                    if (d !== '1')
                        {
                        alert(d);
                        }
                    else
                        {
                        alert('Filename: ' + c.name + ' was uploaded');
                        }
                  }
Run Code Online (Sandbox Code Playgroud)

加上这个版本的uploadify脚本

<?php

    if (!empty($_FILES)) 
    {
        $tempFile = $_FILES['userfile']['tmp_name'];

        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
        $targetFile =  str_replace('//','/',$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"; } // This is required for onComplete to fire on Mac OSX
    echo $stringData;
?>
Run Code Online (Sandbox Code Playgroud)

  • 似乎没有办法获得HTTP响应主体.因此,从服务器向输出提供更多有用的错误消息是无用的,因为您无法显示它们. (3认同)
  • 在尝试之后,onComplete似乎在发生错误时不会触发.所以就我现在看来,如果出现错误,就无法进入http响应主体.因此,问题仍然存在.是时候联系上传的作者,并问他为什么不提供访问http响应机构的onError ... (2认同)