hello friends i want to save image from my wamp server to my specific wamp project folder i have used below code ,this code show me the dialog to save image but i want to call image from wamp server and save it in my folder
<?php
header('Content-type: image/png');
$imageUrl = "http://ip/demo/images/itemimage/Platters.png";
$filename = realpath(dirname("http://ip/demo/images/itemimage/Platters.png"))."/image1.png";
$handle = file_get_contents($imageUrl);
file_put_contents($filename, $handle);
?>
this code do not download image automatically to my folde can any one help me ? i got ths error with above code
The problem is you do two things on your script. You set the image to deliver the image over the php script.
<?php
header('Content-type: image/png');
echo file_get_contents("http://ip/demo/images/itemimage/Platters.png");
?>
Then you should fetch the image and send the image with echo to the user.
When you want to save the image then you need only fetch the image with file_get_contents and put them to your harddrive what you do at the moment.
I think in your example the echo missing this is why you get the error. You set the content type of the site but you don't deliver any png data.
<?php
header('Content-type: image/png');
$handle = file_get_contents("http://ip/demo/images/itemimage/Platters.png");
file_put_contents(dirname(__FILE__).md5(time()), $handle);
echo $handle;
?>
Edit: Try something like this. Then he should save the image in the same path.
单程:
exec("wget http://ip/demo/images/itemimage/Platters.png /tmp/demo/images/itemimage/Platters.png");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.