Jump to content


rename on upload

  • Please log in to reply
2 replies to this topic

#1 gurechan

  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 07 July 2006 - 01:26 PM

Hi, I am trying to set up an upload script in php using:

$updir = "../files/";
$file = $_FILES['file']['name'];
if(!(copy($_FILES['file']['tmp_name'], $updir . $_FILES['file']['name']))) die("Cannot upload files.");

What I want to do though is rename the file on upload. For examle:

From: abc.some_file_extension
To: 123.some_file_extension

Can anyone point me in the right direction?

#2 SharkBait

  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 07 July 2006 - 02:45 PM

When I upload a file I tend to do rename it with the move_uploaded_file() function.

if(move_uploaded_file($_FILES['file']['tmp_name'], $updir . $newFilename)) {
  // file was moved and renamed
} else {
  // There was an error moving the file

#3 shocker-z

  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 07 July 2006 - 02:50 PM

$updir = "../files/";
$file = explode('.',$_FILES['file']['name']);
if(!(copy($_FILES['file']['tmp_name'], $updir . $newfile))) die("Cannot upload files.");

That should do the job not sure if the quickest way and not tested..

The count($file) is incase the file has any .'s in the name so it will always use the last text after the .

sorry wrote this and SharkBait replyed.. just thought i would post anyway as this will make it so you keep the extention of the file..

www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users