note 54804 deleted from reserved.variables by philip
| From: | philip@php.net | Date: | Wed, 21 Feb 2007 16:07:33 +0000 |
| Subject: | note 54804 deleted from reserved.variables by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123650@lists.php.net to get a copy of this message | ||
Note Submitter: php at php-universe dot com
----
While recently working on a file upload script, that works on moving files and resizing images based
upon their extension, I found a great way to determine the file extension.
<?
function get_extension($filename)
{//start get_extension function
return (count($tmp = explode('.',basename($filename)))>1)?array_pop($tmp):'';
}//end get_extension function
/* An example use of this function:*/
foreach($_FILES as $files)
{//foreach $_FILES action
if($files['error']==0)
{//if the file was successfully uploaded
$ext = "<br />.".get_extension($files['name']);
echo $ext;
}//end of successfull upload check
}//end foreach $_FILES
?>
This returns the file extension for each of the files uploaded, giving something like:
.jpg
.swf