![]() |
Image Uploading
When making an upload script, does the name key ( e.g.
PHP Code:
PHP Code:
|
Edit: I feel like an idiot. Yes it does contain the extention. But the type var does not contain data like .jpg
PHP: Handling file uploads - Manual A complete reference on that. For your question, type returns the MIME type. But do NOT rely on this because it is not checked for authenticity and can be forged. What I do is this PHP Code:
Note: We subtract one from sizeof because it starts at one, not zero like arrays do. |
You state that people shouldn't rely on the MIME type passed along with the uploaded file, because it is not checked for authenticity and can be forged, but have no qualms with 'trusting' the file extension?
Also, using an alternative method, the extension can be grabbed with: $ext = pathinfo($filename, PATHINFO_EXTENSION);Finally, to answer the original question posed by Orc, $_FILES[...]['name'] will contain the name of the file as sent by the browser (eg. myimage.jpg), extension and all. |
If the files name extension is correct it cannot pose a threat, the server runs files based off what those letters are. It doesn't matter what code you put in a jpg, it cant execute a script unless there is some serious error with the server OS.
|
Thanks guys. I was just trying to only strict .GIF .PNG .JPG image types, to others by throwing an exception if they don't match with gif nor png nor jpg.
|
Im in the process of developing a fileserver platform for personal use and for the fun of it, powered by PHP5 and MySQL.
And so far i´ve built in Mime checks, and Size checks. and will use Salathe´s method to check the file extensions also. For double security. Would one check for something else ? I was thinking about using some image functions to make sure "image.jpg" are in fact a image file. /EyeDentify |
Either one should work, I dont see why you need to be redundant. If you want to make tripple sure it is a valid image, run it though a GD process, it will return an error if the image isnt valid. Although for speed reasons that would be a ridiculous measure.
|
| All times are GMT. The time now is 10:42 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0