Blueimp jQuery 文件上传插件——“空文件上传"结果 PHP

2023-12-01php开发问题
2

本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17