1. Computing

Discuss in my forum

Extracting the File Extension

Finding the file extention in the file name

By , About.com Guide

 function findexts ($filename) 
 { 
 $filename = strtolower($filename) ; 
 $exts = split("[/\\.]", $filename) ; 
 $n = count($exts)-1; 
 $exts = $exts[$n]; 
 return $exts; 
 } 
 
This function is used to find the file extension. If you wanted to rename a file upload you would still need to keep the extension. We can use this function to find it. Once found it can be appended to the end of a random number or a timestamp (or other naming system you choose) to use as the file name.

Basically what the code is doing is first using strtolower to change the extension (and the whole file name) into lower case, just to keep it clean. Next we are splitting the filename into an array using split. By splitting it at the [.] the extension will be the last element in the array, which we then return.

  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Step By Steps
  5. Find File Extension PHP - Strip File Extension PHP - PHP file ext

©2013 About.com. All rights reserved.