note 54804 added to reserved.variables
| From: | php at php-universe dot com | Date: | Fri, 15 Jul 2005 12:11:16 +0000 |
| Subject: | note 54804 added to reserved.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92022@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/reserved.variables.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54804
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54804&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54804&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54804&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54804&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54804&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54804&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54804&report=yes
Search -- http://master.php.net/manage/user-notes.php