Jump to content

Renaming a image file


markyoung1984

Recommended Posts

I have the following code:

$temp1 = 'images\prodinitial\copimage.jpg';

$temp2 = 'images\prodinitial\copimage_1.jpg';

 

rename($temp1,$temp2);

 

Even if I try double back slash (to account for the escape sequence), I still get the error "[function.rename]: No such file or directory"

 

I'm working on a Windows machine with XAMPP.  Its driving me crazy and I can't see whats wrong.  The file the command is being launched from is in the same folder as the images folder that the command references.  Why is it so hard to simply rename a file?

Link to comment
https://forums.phpfreaks.com/topic/142498-renaming-a-image-file/
Share on other sites

If the script is in the same file as the images folder, this would work:

 

            $temp1 = '\prodinitial\copimage.jpg';
            $temp2 = '\prodinitial\copimage_1.jpg';

            rename($temp1,$temp2);

 

If you want to use the paths you would need to use the full paths and should look at $_SERVER['DOCUMENT_ROOT'] for that.

try this:

if(!is_dir('images')) die("images doesn't exist");
if(!is_dir('images/prodinitial')) die("images/prodinitial doesn't exist");
$temp1 = 'images/prodinitial/copimage.jpg';
$temp2 = 'images/prodinitial/copimage_1.jpg';
rename($temp1,$temp2);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.