How do I test if the file uploaded has returned an error using blueimps file uploader.
The uploader only allows a single file upload (must be an image).
I have the following js code
<script>
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
singleFileUploads: true ,
submit: function (e, data) {
$('#upload_overlay').fadeIn(300);
},
done: function (e, data) {
if(typeof data.files.error == "undefined"){
$('#err_succ_msg').html('Photo successfully updated.').css('background-color','#B1DD8B').show(1);
$('#upload_overlay').fadeOut(300);
}
else{
$('#err_succ_msg').html('Photo update failed. Please try again.').css('background-color','#F76151').show(1);
$('#upload_overlay').fadeOut(300);
}
},
fail: function (e, data) {
$('#err_succ_msg').html('Photo update failed. Please try again.').css('background-color','#F76151').show(1);
$('#upload_overlay').fadeOut(300);
}
});
});
</script>
In the "done" function I'm trying to find out if there is a error so I can show the correct message to the user.
I've tried "alerting" out data.result[0].error and data.files[data.index].error but it either comes out blank or has a "data.result[0]" is undefined.
Mostly from this question here: blueImp/jquery file upload - How do I get the error message if the file type was not accepted?
also on the PHP side of things how do I check if there is an error. For example the PHP index file has this:
require('UploadHandler.php');
$upload_handler = new UploadHandler();
What do I need to figure out if there is an error so I do some processing on the server side?