How to check if the downloaded file is an image? [file sent via the HTML5 file API received via php: // input]

I am working with the HTML5 API ( tutorial here ) and I need to check if the file is an image or not. The main problem is that during normal boot, I could also call getimagesize(), as a parameter, the path to a temporary file, and then decide whether to save it on the server or not.

However, with the file upload API, files are obtained with php://input, which returns the actual transfer bits.

What is the best way to check in this situation? Should I store the bit in a physical location and then check it and delete after it, or is this the best way?

Thank.

+1
source share
1 answer

Should this image be stored on disk? If so, then I would say that the best way is to create a temporary file, write the data, and then check if this image is a regular function if it moves the temporary file to its final destination, otherwise just delete it.

If for some reason you do not want to do this, you can check the magic numbers in the input ( here is a more complete list ). However, do not forget that this is more likely a failure than conventional solutions.

+1
source

All Articles