Blueimp jQuery File Upload plugin - quot;Empty file uploadquot; result PHP(Blueimp jQuery 文件上传插件——“空文件上传结果 PHP)
问题描述
这是插件:https://github.com/blueimp/jQuery-File-Uploadp>
上传文件后,我无法从插件获取我想要的响应.
在带有插件的页面上,我有以下内容
$('#fileupload').fileupload('选项',{'maxNumberOfFiles' :1,网址":/admin/upload_handler.php"});在 upload_handler.php 中,我成功地从 $_FILES 检索上传的文件并执行操作,然后以 JSON 格式发回响应.我已使用 Firebug 确认响应格式正确:
<代码>[{url":image_url",thumbnail_url":image_th_url",delete_url":测试",删除类型":删除",名称":foobar.jpg",尺寸":7419}]但是回调找不到文件数组,我得到错误:'空文件上传结果'.我觉得我在这里遗漏了一些重要的东西——我在文档、论坛或 Stack Overflow 中找不到任何东西.感谢您的帮助.
从插件版本5开始,json响应发生了变化:https://github.com/blueimp/jQuery-File-Upload/wiki/JSON-Response
所以你只需要调整你的上传类:
$filejson = new stdClass();$filejson->files[] = $fileArray;返回 json_encode($filejson);你已经完成了
Here's the plugin: https://github.com/blueimp/jQuery-File-Upload
I'm having a problem getting the response I want from the plugin after uploading a file.
On the page with the plugin, I have the following
$('#fileupload').fileupload(
    'option',
    {
        'maxNumberOfFiles' :1,
        'url' : '/admin/upload_handler.php'
    }
);
In upload_handler.php I successfully retrieve the uploaded files from $_FILES and do stuff, then send a response back in JSON. I've confirmed using Firebug that the response is in the proper format:
[ 
    {                
        "url" : "image_url",
        "thumbnail_url" : "image_th_url",
         "delete_url" : "test",
         "delete_type" : "DELETE",
         "name" : "foobar.jpg",
         "size" : 7419
     }
]
But the callback can't find the files array, and I get the error: 'Empty file upload result'. I feel like I'm missing something crucial here--I can't find anything in the docs, forums, or Stack Overflow. I appreciate any help.
Since the version 5 of the plugin, the json response has changed: https://github.com/blueimp/jQuery-File-Upload/wiki/JSON-Response
So you just have tweak your upload class with:
$filejson = new stdClass();
$filejson->files[] = $fileArray;
return json_encode($filejson);
And you're done
这篇关于Blueimp jQuery 文件上传插件——“空文件上传"结果 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Blueimp jQuery 文件上传插件——“空文件上传"结果 PHP
				
        
 
            
        基础教程推荐
- php中的PDF导出 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				