note 39182 deleted from function.move-uploaded-file by didou
| From: | didou@php.net | Date: | Tue, 20 Jan 2004 10:26:44 +0000 |
| Subject: | note 39182 deleted from function.move-uploaded-file by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63870@lists.php.net to get a copy of this message | ||
Note Submitter: magnet_internet@hotmail.com
----
Get your extension this way as well...this avoids problems if you have more than one '.'
in the filename. It will only match on the end of the string.
<?php
$FileName = "myfile.jpg";
preg_match("/\.(jpg|gif|png)$/i",$FileName,$Extension);
echo "The extension is " . $Extension[0];
?>
Returns "The extension is .jpg".
$Extension[1] would return "The extension is jpg", [1] being the memorized match from
what's in the parentheses in the regular expression.
Of course, modify the regular expression to match the extensions you're looking for. /i is
added for case insensitivity.