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

Renaming PHP Uploads

By Angela Bradley, About.com

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']) ;

Index: Renaming PHP Uploads

  1. Uploading the file
  2. Finding the Extention
  3. A Random File Name
  4. Saving the file with the new name

2 of 4

Explore PHP / MySQL

More from About.com

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

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

All rights reserved.