Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Simple Image Swap?

$
0
0

I have two files on a server, and I want to swap filenames like this:

 

image1.jpg -> image2.jpg

image2.jpg -> image1.jpg

 

I cannot get this to work.  Obviously I cannot do it this way because then I would end up with two copies of the same file, so I have tried this:

 

 

$file1 = "image1.jpg";
$file2 = "image2.jpg";
$temp1 = "temp1.jpg";
$temp2 = "temp2.jpg";

rename($file1, $temp1);
rename($file2, $temp2);
rename($temp1, $file2);
rename($temp2, $file1);
 

 

 

 
Also, I have tried this:
 

 

$file1 = "image1.jpg";
$file2 = "image2.jpg";
$temp1 = "temp1.jpg";
$temp2 = "temp2.jpg";

copy($file1, $temp1);
copy($file2, $temp2);
unlink($file1);
unlink($file2);
rename($temp1, $file2)
rename($temp2, $file1);
 

 

I have spent about 3 hours on this seemingly simple code  :(   Please have mercy on me!   ;)


Viewing all articles
Browse latest Browse all 13200

Trending Articles