我正在使用 https://github.com/blueimp/jQuery-File-Upload 中的 jQuery 文件上传 jQuery UI 插件 8.7.2 上传和删除文件工作成功。 但是,在服务器端删除文件未正确完成时,我应该在响应 JSON 中返回什么以显示错误。例如,用户无权访问此内容。
这是我的 PHP 代码:
$response = json_encode(
(object)
[ 'files' =>
[
$file->filename => true,
]
]
);
return $response;
最佳答案
这是我在 Laravel 中的做法。您应该更改循环来处理 POST 中收到的所有文件
$json = array(
'files' => array()
);
foreach( $request->files as $file ){
$filename = $file->getClientOriginalName().".".$file->getClientOriginalExtension();
$json['files'][] = array(
'name' => $filename,
'size' => $file->getSize(),
'type' => $file->getMimeType(),
'error' => "Your error message"
);
}
// Return error
return response($json); //Laravel: the array get converted to json. You could call json_encode and pass it to your response
关于javascript - 我应该返回什么来响应在 blueimp/jquery.file-upload-ui 的删除事件上显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29826573/