Michan Posted February 15, 2008 Share Posted February 15, 2008 I'm trying to rename/move a JPG that I've created and is being stored on the server, but occasionally (say, 1/5 times), it won't move. It gives me the following error: Warning: rename(gallery/temp/462/thumb.jpg,gallery/2008/02/15/462-1203093027_m.jpg) [function.rename]: No such file or directory in /home/.kaybill/clubski/mydomain.com/submit.php on line 96 The file exists: gallery/temp/462/thumb.jpg The dir exists, and is chmodded appropriately: gallery/2008/02/15/ The code (on line 96) is: rename('gallery/temp/'.$_POST['user'].'/thumb.jpg', 'gallery/'.$year.'/'.$month.'/'.$day.'/'.$_POST['user'].'-'.time().'_m.jpg'); Why, oh why does it randomly not move the file? This is becoming very frustrating, as my code seems to be fine (as it's doing it the majority of times). Just of note, the files are also very small in size -- that one is around 22 KB. The images it chooses not to move seem to be random. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/91281-failing-to-renamemove-image/ Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 Have you tried using the full path? rename("/home/you/public_html/temp/".$_POST['user']."/file.jpg", "/home/you/public_html/gallery/".$year."/".$month."/".$day."/'.$_POST['user']."-"time()."_m.jpg"); Link to comment https://forums.phpfreaks.com/topic/91281-failing-to-renamemove-image/#findComment-467791 Share on other sites More sharing options...
Michan Posted February 15, 2008 Author Share Posted February 15, 2008 Have you tried using the full path? rename("/home/you/public_html/temp/".$_POST['user']."/file.jpg", "/home/you/public_html/gallery/".$year."/".$month."/".$day."/'.$_POST['user']."-"time()."_m.jpg"); I'll give it a try, but seeing as it works most of the time, surely this wouldn't be the case? Link to comment https://forums.phpfreaks.com/topic/91281-failing-to-renamemove-image/#findComment-467794 Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 Well try using file_exists before trying to move the first file $file = "/home/you/public_html/temp/".$_POST['user']."/file.jpg"; if(file_exists($file)){ //rename that to move it }else { //file doesn't exist } Link to comment https://forums.phpfreaks.com/topic/91281-failing-to-renamemove-image/#findComment-467805 Share on other sites More sharing options...
Michan Posted February 15, 2008 Author Share Posted February 15, 2008 Well try using file_exists before trying to move the first file $file = "/home/you/public_html/temp/".$_POST['user']."/file.jpg"; if(file_exists($file)){ //rename that to move it }else { //file doesn't exist } Thanks, I wasn't aware of that function. However, the file exists, and the problem is persisting. Link to comment https://forums.phpfreaks.com/topic/91281-failing-to-renamemove-image/#findComment-467815 Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 Try checking if the folder you're trying to move exists if(is_dir("/new/folder/where/file/is/to/be/stores")){ //rename }else { //fail } Link to comment https://forums.phpfreaks.com/topic/91281-failing-to-renamemove-image/#findComment-467817 Share on other sites More sharing options...
Michan Posted February 15, 2008 Author Share Posted February 15, 2008 Try checking if the folder you're trying to move exists if(is_dir("/new/folder/where/file/is/to/be/stores")){ //rename }else { //fail } Hmm, for some reason it will work constantly for a while, then all of a sudden, it'll decide not to (files and folders are the same, and exist). The same error is produced Link to comment https://forums.phpfreaks.com/topic/91281-failing-to-renamemove-image/#findComment-467831 Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 try storing the new and old folder/file names in a variable and echo them out, seem if they are what you want Link to comment https://forums.phpfreaks.com/topic/91281-failing-to-renamemove-image/#findComment-467837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.