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! Quote Link to comment 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"); Quote Link to comment 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? Quote Link to comment 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 } Quote Link to comment 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. Quote Link to comment 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 } Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.