gurechan Posted July 7, 2006 Share Posted July 7, 2006 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_extensionTo: 123.some_file_extensionCan anyone point me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/13951-rename-on-upload/ Share on other sites More sharing options...
SharkBait Posted July 7, 2006 Share Posted July 7, 2006 When I upload a file I tend to do rename it with the move_uploaded_file() function.[code]<?phpif(move_uploaded_file($_FILES['file']['tmp_name'], $updir . $newFilename)) { // file was moved and renamed} else { // There was an error moving the file}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13951-rename-on-upload/#findComment-54405 Share on other sites More sharing options...
shocker-z Posted July 7, 2006 Share Posted July 7, 2006 $updir = "../files/";$file = explode('.',$_FILES['file']['name']);$extention=count($file);$newfile='new_file_name'.'.'.$file[$extention];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..RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/13951-rename-on-upload/#findComment-54408 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.