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

Link to comment
Share on other sites

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);

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.