jandrews3 Posted March 30, 2010 Share Posted March 30, 2010 I know someone's gonna paste me for this, for I certainly know NOT what I do ... but ... shouldn't the following code when executed change the name of a file called test2.pdf in a directory called documents to rename_test.pdf? <? $old_name = "test2.pdf"; $new_name = "rename_test.pdf"; rename("/documents/".$old_name, "/documents/".$new_name); ?> Quote Link to comment https://forums.phpfreaks.com/topic/197015-rename/ Share on other sites More sharing options...
mikesta707 Posted March 30, 2010 Share Posted March 30, 2010 yes, yes that should do exactly that (assuming the script is in the same directory as the documents directory) Quote Link to comment https://forums.phpfreaks.com/topic/197015-rename/#findComment-1034243 Share on other sites More sharing options...
gwolgamott Posted March 30, 2010 Share Posted March 30, 2010 And assuming you have r/w privileges too. Quote Link to comment https://forums.phpfreaks.com/topic/197015-rename/#findComment-1034245 Share on other sites More sharing options...
jandrews3 Posted March 30, 2010 Author Share Posted March 30, 2010 Yes, its in the same directory as documents, but I'm getting the following error: Warning: rename(/documents/test2.pdf,/documents/rename_test.pdf) [function.rename]: No such file or directory in /home/account1/public_html/test_rename.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/197015-rename/#findComment-1034247 Share on other sites More sharing options...
mikesta707 Posted March 30, 2010 Share Posted March 30, 2010 that means that the directory/file you are pointing to doesn't exist. Remember, you are giving a relative path, so make sure that the file is where you expect it to be Quote Link to comment https://forums.phpfreaks.com/topic/197015-rename/#findComment-1034248 Share on other sites More sharing options...
jandrews3 Posted March 30, 2010 Author Share Posted March 30, 2010 I'm afraid the file does exist (I've verified it with my ftp client and also by loading it by URL in a browser) and it is properly placed in the documents folder. Could there be a server setting that doesn't allow renaming files which might give this response? Quote Link to comment https://forums.phpfreaks.com/topic/197015-rename/#findComment-1034251 Share on other sites More sharing options...
jandrews3 Posted March 30, 2010 Author Share Posted March 30, 2010 Found problem. Needed to remove leading slash from path. Strange that php.net has it in their example: rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt"); Quote Link to comment https://forums.phpfreaks.com/topic/197015-rename/#findComment-1034252 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.