note 37328 deleted from function.move-uploaded-file by didou
| From: | didou@php.net | Date: | Tue, 11 Nov 2003 09:53:05 +0000 |
| Subject: | note 37328 deleted from function.move-uploaded-file by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-60231@lists.php.net to get a copy of this message | ||
Note Submitter: 2072@2072productions.com
----
Here is a much better, reliable function to check the extension of an uploaded file:
<?php
function checkext($filename, $search)
{
if (stristr(substr($filename, -4), $search) !== false)
return true;
else return false;
}
?>
This functions look at the 4 last letters of the filename ignoring case, looking only the 3 last
letters is not reliable at all: a file can have no extension...
example, we check if the file is a ".rar" file:
<?php
$thisisararfile = checkext($_FILES["userfile"]["name"],".rar");
if ($thisisararfile)
echo "OK, this is a .rar file!";
?>
Note that the "." must be included in the $search parameter.