views:

61

answers:

3

Why might a file only be partially uploaded?

I am improving error-handling in my PHP file upload script and am trying to figure out how to handle UPLOAD_ERR_PARTIAL properly.

Should I prompt the user to try uploading the file again, or should I inform them that there is a more severe problem which is preventing them from uploading a possibly legitimate file?

Thanks!

+2  A: 

Why might a file only be partially uploaded?

This is usually caused by the user canceling the upload.

Should I prompt the user to try uploading the file again, or should I inform them that there is a more severe problem which is preventing them from uploading a possibly legitimate file?

You should prompt them to try again and if problems continue to contact the site owners, including as much detail as possible.

webbiedave
A: 

UPLOAD_ERR_PARTIAL is given when the mime boundary is not found after the file data. A possibly cause for this is that the upload was cancelled by the user (pressed ESC, etc).

I think it's enough to inform the user that the file is only partially uploaded and a retry will fix the problem.

halfdan
A: 

Well, the file upload could be interrupted by:

Out of space in destination

Connection interruption

Damage file

Wrong name

Wrong extension

etc...

The best you can do is to verify and protect the upload process with does verifications before actually send the file to the server...

The first time I've made a file upload script, I used 1 line of code, now, the same script seems like a web page ;)

EDITED (example for controlling extension and file size):

if ((

($file_up["type"] == "image/gif") ||

($file_up["type"] == "image/jpeg") ||

($file_up["type"] == "image/jpg") ||

($file_up["type"] == "image/pjpeg") ||

($file_up["type"] == "image/bmp") ||

($file_up["type"] == "image/tiff") ||

($file_up["type"] == "image/png")) &&

($file_up["size"] < 1050000))

{

    code if all ok...


}
Zuul
wrong extension? got an example?
Col. Shrapnel
humm... yes, just imagine that your input should only be working with pictures and the user tries to upload a document, if it's supposed to be only pictures, you should deny any other file extensions (view my answer under the edit comment...
Zuul
@Zuul: The question is how would a file name/extension cause a UPLOAD_ERR_PARTIAL?
webbiedave
well, it doesn't... the file extension was just a warning about possible errors that you might encounter... :)Specifically to UPLOAD_ERR_PARTIAL, what Halfdan said seems to be the only reason... so, just inform the user that the process was interrupted, and should try again!
Zuul