forumnz Posted April 6, 2007 Share Posted April 6, 2007 I have here a script that should allow the user to browse for an image and change the name of it. Then click upload and the image will be uploaded under the new name. The image will upload but the name wont change. <?php // directory path. $uploaddir = 'upload_new/'; // get the dir to send file to and the file name. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $file_name=$uploadfile; @rename($file_name,$uplaodfile); // if all the conditions are correct send the file to the directory. if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){ // success echoed echo " <font color='red'>File is valid, and was successfully uploaded.</font>"; }else { //unsuccesfull echoed echo "<font color='red'>File was unsuccesful sorry</font>"; } // show the form. echo" <form enctype='multipart/form-data' action='upload.php' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='30000000000000000000000'> please provide a file name: <br> send this file <input name='file_name' type='text' > <br> send this file <input name='userfile' type='file' > <input type='submit' name='submit' value='Send File'> </form>"; ?> Thanks, Sam. Link to comment https://forums.phpfreaks.com/topic/45915-script-to-upload-and-change-name/ Share on other sites More sharing options...
freakus_maximus Posted April 6, 2007 Share Posted April 6, 2007 @rename($file_name,$uplaodfile); should be @rename($file_name,$uploadfile); Just a possibility, but it is what I saw when I reviewed your code. Link to comment https://forums.phpfreaks.com/topic/45915-script-to-upload-and-change-name/#findComment-223028 Share on other sites More sharing options...
forumnz Posted April 6, 2007 Author Share Posted April 6, 2007 Thanks but that wasn't the problem. Link to comment https://forums.phpfreaks.com/topic/45915-script-to-upload-and-change-name/#findComment-223030 Share on other sites More sharing options...
forumnz Posted April 6, 2007 Author Share Posted April 6, 2007 Help please? Its just the problem that it wont save under the new name now. Thanks. Link to comment https://forums.phpfreaks.com/topic/45915-script-to-upload-and-change-name/#findComment-223046 Share on other sites More sharing options...
per1os Posted April 6, 2007 Share Posted April 6, 2007 Why rename the file when you can upload it under the new name? That and your rename function is flawed for a few reasons, first you are calling it on a "non-existent" file. It should be after the move_upload. Second why not just set the name correct in the move_upload file part??? And your are renaming the file "$upload_file" to "$filename" which stores the value of "$upload_file" That does not make any sense at all?????? I would suggest reading the manual and getting your functions straight www.php.net/move_uploaded_file www.php.net/rename I am sure if you look in the user comments for the move_uploaded_file you will find how to rename a file etc. Link to comment https://forums.phpfreaks.com/topic/45915-script-to-upload-and-change-name/#findComment-223062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.