02-04-2008, 05:00 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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.
|
|
|
|