问题
I am using jQuery File Upload jQuery UI Plugin 8.7.2 from https://github.com/blueimp/jQuery-File-Upload Uploading and deleting of files work successfully. But what should I return in response JSON to show error when deleting of file not finished correctly on server side. For example user have not access for this.
This is my PHP code:
$response = json_encode(
(object)
[ 'files' =>
[
$file->filename => true,
]
]
);
return $response;
回答1:
Heres how I do it in Laravel. You should change the loop to deal with all files received in the 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
回答2:
The UI plugin doesn't seem to do anything with the response so you'd need to modify the jquery.fileupload-ui.js code in order to do something with an error response.
来源:https://stackoverflow.com/questions/29826573/what-should-i-return-in-response-to-show-error-message-on-delete-event-for-bluei