gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:33:57 27 4
gpt4 key购买 nike

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

file.jpg (52.78KB) - HTTP Error


表示存在HTTP错误。但这对用户不是很有用。如何使其显示更详细的错误消息?像:“不是有效的图片”或“配额已满”?

我当时正在考虑在HTTP响应正文中传递这些消息,但是Uploadify不会接收它们。是否有已知的方法将错误消息传递回Uploadify?

最佳答案

查看上载论坛中的这两篇有关如何处理错误的文章

onError to display what's happening

Upload script error reporting

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

更新资料

以下似乎对我有用。

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


与此版本的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;
?>

关于uploadify - Uploadify:显示来自HTTP响应的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1877644/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com