Jump to content

Failing to rename/move image


Michan

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.