fle*_*age 5 javascript php error-reporting plupload
我有一个基于来自网站的自定义示例的plupload实例,除了显示来自服务器端上传脚本的错误消息(下载中示例文件夹中的upload.php)之外,它运行完美.
正在显示本地错误消息,例如,如果我尝试上传受限制的文件类型,我会收到我期望的错误消息,但是,服务器端消息没有显示.
我知道upload.php文件正在被正确触发,因为我的上传成功处理,并且我已设置睡眠功能以验证正在请求文件.在那一刻我只是放在upload.php顶部的行,以协助调试,只是睡了10秒钟并返回错误信息,这仍然无法正常工作.
upload.php
sleep(10);
die('{"jsonrpc" : "2.0", "error" : {"code": 500, "message": "THIS IS AN ERROR."}, "id" : "id"}');
...(Rest of normal upload.php file)...
Run Code Online (Sandbox Code Playgroud)
我正在使用的javascript包含在下面,你们可以给予的任何帮助将非常感激,因为我已经花了太长时间在这上面而且这个问题阻碍了我能够推送我的代码.
谢谢,
亚历克斯
// Fanart
$(function() {
var fanart_uploader = new plupload.Uploader({
runtimes : 'html5,flash,html4',
browse_button : 'fanart_pickfiles',
container : 'fanart_container',
drop_element : 'fanart_drop',
chunk_size : '1mb',
max_file_size : '8mb',
url : '/upload.php?gameid=<?= $gameid ?>&arttype=fanart',
flash_swf_url : '/js/plupload/js/plupload.flash.swf',
silverlight_xap_url : '/js/plupload/js/plupload.silverlight.xap',
filters : [
{title : "Image files", extensions : "jpg,png"},
]
});
fanart_uploader.bind('Init', function(up, params) {
$('#fanart_runtime').html("You are using " + params.runtime);
});
$('#fanart_uploadfiles').click(function(e) {
fanart_uploader.start();
e.preventDefault();
});
fanart_uploader.init();
fanart_uploader.bind('FilesAdded', function(up, files) {
$.each(files, function(i, file) {
$('#fanart_filelist').append(
'<div style="padding: 4px; margin: 3px; border: 1px dotted #fff; border-radius: 6px; background-color: #333;" id="' + file.id + '"><img class="tick" src=\"<?= $baseurl ?>/images/common/icons/tick_16.png\" style=\"display: none; vertical-align: -2px;\" />' +
file.name + ' <em>(' + plupload.formatSize(file.size) + ')</em> <div style=\"margin: auto; margin-top: 3px; width: 200px; height: 20px; border: 1px solid #fff; border-radius: 6px; background-color: #222;\"><div class="progressbar" style=\"width: 0px; height: 16px; padding: 2px 0px; background-color: #ccc; border-radius: 6px; text-align: center;\"><b style="font-size: 16px; color: #222;"></b></div></div>' +
'</div>');
});
up.refresh(); // Reposition Flash/Silverlight
});
fanart_uploader.bind('UploadProgress', function(up, file) {
$('#' + file.id + " b").html(file.percent + "%");
$('#' + file.id + " .progressbar").css("width", (file.percent * 2));
});
fanart_uploader.bind('Error', function(up, err) {
$('#fanart_filelist').append("<div>Error: " + err.code +
", Message: " + err.message +
(err.file ? ", File: " + err.file.name : "") +
"</div>"
);
up.refresh(); // Reposition Flash/Silverlight
});
fanart_uploader.bind('FileUploaded', function(up, file) {
$('#' + file.id + " .tick").show();
});
});
Run Code Online (Sandbox Code Playgroud)
Mic*_*son 10
以下是您链接的答案:
NM,回答了我自己的问题......
似乎我的plUpload实例将服务器响应(JSON字符串)释放到JS对象中,可以通过"FileUploaded"事件访问该对象.
这是需要此答案的任何其他人的代码示例.
Run Code Online (Sandbox Code Playgroud)fanart_uploader.bind('FileUploaded', function(up, file, info) { $('#' + file.id + " .tick").show(); printObject(info); var response = jQuery.parseJSON(info.response); alert(response.error.message); });