note 82233 deleted from features.file-upload by googleguy
| From: | googleguy@php.net | Date: | Wed, 22 Aug 2012 01:52:39 +0000 |
| Subject: | note 82233 deleted from features.file-upload by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190168@lists.php.net to get a copy of this message | ||
Note Submitter: dev at arthurk dot com
----
Here is a quick and easy way to get the base name and the extension of a file.
I noticed that many examples here use explode(...), however this doesn't handle filenames like
foo-1.0.1.tar gracefully. This code does. (foo-1.0.1 is the base, and .tar is the extension).
<?php
$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
$file_ext = substr($filename, strripos($filename, '.'));
?>
Notice the use of "strripos()" instead of "stripos()".
If you need to detect .tar.gz, etc. as the ext (starting at the first dot), substitute
"stripos" for "strripos".