note 82233 added to features.file-upload

From: Date: Wed, 02 Apr 2008 06:44:47 +0000
Subject: note 82233 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-137843@lists.php.net to get a copy of this message
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". ---- Server IP: 209.41.74.194 Probable Submitter: 24.9.128.209 ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.php Edit -- https://master.php.net/note/edit/82233 Del: integrated -- https://master.php.net/note/delete/82233/integrated Del: useless -- https://master.php.net/note/delete/82233/useless Del: bad code -- https://master.php.net/note/delete/82233/bad+code Del: spam -- https://master.php.net/note/delete/82233/spam Del: non-english -- https://master.php.net/note/delete/82233/non-english Del: in docs -- https://master.php.net/note/delete/82233/in+docs Del: other reasons-- https://master.php.net/note/delete/82233 Reject -- https://master.php.net/note/reject/82233 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137843) next »