1. Home
  2. Computing & Technology
  3. PHP / MySQL

Renaming PHP Uploads

By , About.com Guide

2 of 4

Finding the Extention

Next we will use a function explained here, to look at the file name and take off the extension for us to use later when we reassign it a new name.
<?php
//This function separates the extension from the rest of the file name and returns it
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}

//This applies the function to our file
$ext = findexts ($_FILES['uploaded']['name']) ;
Explore PHP / MySQL
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Advanced PHP
  5. Preserve the file extension in a PHP rename

©2009 About.com, a part of The New York Times Company.

All rights reserved.