Sometimes images get corrupted, and can not be uploaded correctly using php. Where I work this happened once in a while, and I did not know how to fix it. When a user sent me an image by email, I could at least recognize the error – It was “Corrupt JPEG data: XXXX extraneous bytes before marker XxXX”.
Having known this I could google it, but the solution was not easy to find because the problem was not in PHP, but in the image. Anyway, the fix was simple. Just ignore the error by adding this to the code:
An other solution is to save the file again with a program like Photoshop(that can open these rare corrupted jpegs) – then it is saved correctly as an uncorrupted jpeg file and can be uploaded.