Uploadify:显示来自 HTTP 响应的错误消息 [英] Uploadify: show error message from HTTP response
问题描述
如果服务器在使用 Uploadify 上传文件时返回错误(HTTP 响应代码 != 200),则上传的文件将变为红色背景并显示如下消息:
file.jpg (52.78KB) - HTTP 错误
表示存在 HTTP 错误.但这对用户来说不是很有用.如何让它显示更详细的错误信息?比如:图片无效"或配额已满"?
我想在 HTTP 响应正文中传递这些消息,但 Uploadify 没有接收它们.有没有已知的方法可以将错误消息传回 Uploadify?
看看uploadify 论坛中的这两篇帖子如何处理错误
里面有很多有用的信息..
更新
以下内容似乎对我有用..
'onComplete': function(a, b, c, d, e){如果 (d !== '1'){警报(d);}别的{alert('文件名:' + c.name + '已上传');}}
加上这个版本的uploadify脚本
If the server returns an error (HTTP response code != 200) when uploading a file with Uploadify, the uploaded file gets a red background and a message is show like this:
file.jpg (52.78KB) - HTTP Error
indicating that there was a HTTP Error. But that's not very useful to the the user. How can I make it show a more detailed error message? Like: 'Not a valid image' or 'Quota full'?
I was thinking of passing those messages in the HTTP response body, but Uploadify doesn't pick them up. Is there a known way to pass error messages back to Uploadify?
Take a look at these two posts in the uploadify forum on how to handle errors
onError to display what's happening and Upload script error reporting
there is a lot of useful info in there ..
Update
The following seems to do the trick for me ..
'onComplete': function(a, b, c, d, e){
if (d !== '1')
{
alert(d);
}
else
{
alert('Filename: ' + c.name + ' was uploaded');
}
}
coupled with this version of the uploadify script
<?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;
?>
这篇关于Uploadify:显示来自 HTTP 响应的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!