Thread: Image Uploading
View Single Post
Old 02-04-2008, 05:00 PM   #2 (permalink)
Village Idiot
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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:
$filetype2 explode('.',$file_name);
$filetype $filetype2[sizeof($filetype2)-1];
$filetype strtolower($filetype);


if(
$filetype == 'jpeg' ||
$filetype == 'jpg')
{
//continue

That gets the value after the last period (so filename.jpg.php cant trick it like it can some). As long as the last extension is acceptable, the server will run it as that no matter what content.

Note: We subtract one from sizeof because it starts at one, not zero like arrays do.
__________________

Village Idiot is offline  
Reply With Quote