if($_FILES['image']['type'] == 'image/jpeg'){
Never rely on the MIME type sent by the browser.
In this case, your problem is that David refers to: IE usually (erroneously) supplies image/pjpeg for JPEG, so you discover an unknown file type and set $ error to Error: The image could not be uploaded. It must be in .jpg, .jpeg or .gif format. Error: The image could not be uploaded. It must be in .jpg, .jpeg or .gif format. ... but then, despite this, you still try to move the file anyway, despite the fact that the value is not set to $ small or $ large.
But more than that, the type passed by the browser is likely to be completely wrong. You cannot trust the downloaded file name or media type to make them suitable, so don't even bother checking them. Instead, look at $imgsize[2] after your call to getimagesize to see what type of PHP is considered an image.
And ... if you accept image downloads from regular users, you have a security issue. It is entirely possible to create a valid GIF (or other type of file) containing HTML tags. Then, when the bloody-dumb-IE arrives to access the GIF as a page on its own, it will detect the HTML tags, decide that the Content-Type you said should be wrong, and instead interpret it as an HTML page, including any javascript that then runs in the security context of your site.
If you need to allow downloading files from an untrusted source and you donβt process the images yourself (which is usually due to the side effect of removing unwanted HTML), you usually have to display your images from a different host name, avoid scripting them on your site.
bobince Oct 23 '09 at 17:53 2009-10-23 17:53
source share