开发者

Uploadify displays complete even if upload is unsuccessful

开发者 https://www.devze.com 2023-02-07 01:54 出处:网络
I\'m using uploadify straight out of the box, I havnt modified it in any way. It\'s uploading files great, so now I\'ve got that sorted I wanted to sort out what happens if the file doesn\'t upload fo

I'm using uploadify straight out of the box, I havnt modified it in any way. It's uploading files great, so now I've got that sorted I wanted to sort out what happens if the file doesn't upload for any reason. I deleted the upload directory from the server so that the file can't be uploaded and tested what would happen. Unfortunately the uploader still says the file has been completed even though no upload directory exists, and the file hasnt been uploaded. I then modified the uploadify.php script开发者_开发百科 so that the file doesn't get saved if it's the wrong file format. This worked great and prevented any files in the wrong format from being saved however the uploader still says the upload is complete. Does anyone know why this might be and what I can do to force an error?

Thanks


Found sort of a solution here:

http://www.uploadify.com/forums/discussion/6940/problems-triggering-onerror/#Item_4

at the bottom.

Basically it says if you want to return an error then do:

header("HTTP/1.0 404 Not Found");
exit;

It's a bit of a hack though because it might not be a 404 error you wish to return. It does the job though


It looks from the documentation as if you need to use the "onError" option and possibly return "false" in the function you supply to it.

e.g.

$('#file_upload').uploadify({
  'uploader'    : '/uploadify/uploadify.swf',
  // Point to a non-existent back-end file so the error always triggers.
  'script'      : '/uploadify/uploadify-x.php',
  'cancelImg'   : '/uploadify/cancel.png',
  'folder'      : '/uploads',
  'onError'     : function (event,ID,fileObj,errorObj) {
      alert(errorObj.type + ' Error: ' + errorObj.info);
    }
});

See:

http://www.uploadify.com/documentation/events/onerror/

Regards Neil

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号