Ok i have a problem i cant solve

I have 2 images

image one saved in location x and has name x1


image two is saved in location y and has name y1


Now i want a script that picks up image y1 and replaces x1 with y1 using changeing the name of the image to x1 as well.


this is what i tried so far but it has not work let me know if i am on the right track my php is rusty

// make a note of the current working directory, relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

echo $newImg = file_get_contents('$directory_self/newImage/STC2033375M1.01.jpg');

echo "<br/>";


echo $fp = fopen('$directory_self/images/', 'w');

echo "<br/>";
echo fwrite($fp, $newImg, strlen($newImg));
fclose($fp);


echo "I ran the script the targetImage now looks like this <br/> <img src='images/targetImage.jpg'  width='300' />";

here is the link to my example that does not work

-- link removed (no longer available) --

I managed to this to work on my localhost so I guess its working now

Crazy man thanks

note: i did not need to use the rename function it just overwrites it using the same name that exists

this is amazing.

Thanks man I spent 3 days trying to find a solution to this and its so nice and clean

<?php
//$thisdir = getcwd(); // dont need this for localhost

// This is the file we want to transfer
$file = 'newImage/STC2033375M1.01.jpg';


// this is wher we want to store it
$newfile = 'images/TargetImage.jpg';





if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.