Why might a file only be partially uploaded?

19,765

Solution 1

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.

Solution 2

UPLOAD_ERR_PARTIAL is given when the mime boundary is not found after the file data. A possible 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.

Solution 3

This is an old post, but I had a random problem of UPLOAD_ERR_PARTIAL, and post my solution.

The problem is that after 2/3 upload I obtained an error of UPLOAD_ERR_PARTIAL, without any interruption by the client.

My problem was related to the Keep-Alive server.

I solved it by inserting at the end of the PHP script for uploading

header ("Connection: close");

that forces the closure of the connection. This has solved my problem.

I hope someone can help.

Thank to this LINK

Solution 4

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...
    
    
}

Solution 5

This may help some people, but I had the same problem. My solution was to uninstall libapache2-mod-php5filter and replace it with the classical libapache2-mod-php5

Share:
19,765

Related videos on Youtube

Mike Moore
Author by

Mike Moore

Updated on July 27, 2020

Comments

  • Mike Moore
    Mike Moore almost 4 years

    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?

  • Zuul
    Zuul almost 14 years
    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...
  • webbiedave
    webbiedave almost 14 years
    The question is how would a file name/extension cause a UPLOAD_ERR_PARTIAL?
  • Zuul
    Zuul almost 14 years
    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!
  • tmsppc
    tmsppc over 12 years
    +1 for clarifying "when the mime boundary is not found after the file data"
  • Treemonkey
    Treemonkey over 10 years
    Worked for me! I spent hours thinking my script was failing / flakey seems that it was the server.
  • Alex Ball
    Alex Ball over 10 years
    @Treemonkey happy to be useful ;-)
  • Meetai.com
    Meetai.com over 10 years
  • Ingwie Phoenix
    Ingwie Phoenix about 9 years
    @Seb Totally +1'd that one as well. Was running into a similar issue and that little side-note got me to the source. :)
  • tonix
    tonix about 8 years
    How should we handle this case on the client side with JS and on the server side with PHP? I mean, if the user starts an upload of a file and then clicks on a cancel button on the page while the file is still being uploaded, I can call .abort() how will PHP receive the information that the user canceled the upload?
  • karllindmark
    karllindmark about 8 years
    In my case, I forgot the leading -- on the last (in this case following) boundary. Lesson learned :-)
  • Box Box Box Box
    Box Box Box Box over 7 years
    @yellowantphil looks like a borderline answer to me
  • globalSchmidt
    globalSchmidt almost 6 years
    @halfdan - I'm not understanding why a mime boundary would be missing. Doesn't PHP handle the boundaries? Alternatively, when a program saves a file (a PDF or pptx in my case), aren't the beginning and end of the file set by the program used?
  • georaldc
    georaldc about 5 years
    I see this answer given out a lot but it would be great if someone could explain why forcing keepalive to be disabled would work.
  • Andrew Koster
    Andrew Koster almost 2 years
    "contact the site owners"???