我正在使用 jQuery 文件上传 jQuery UI 插件 8.7.2https://github.com/blueimp/jQuery-File-Upload https://github.com/blueimp/jQuery-File-Upload上传和删除文件工作成功。
但是,在服务器端删除文件未正确完成时,我应该在响应 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)