[英]download image from wamp server and save in my folder loacated in same using php
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 你好朋友,我想将图像从我的wamp服务器保存到我的特定wamp项目文件夹中,我已经在下面的代码中使用过,此代码向我显示了对话框以保存图像,但是我想从wamp服务器中调用图像并将其保存在我的文件夹中
<?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脚本传递图像。
<?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. 当您要保存图像时,只需要使用file_get_contents来获取图像,然后将它们放入硬盘即可。
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.
您设置了网站的内容类型,但没有传递任何png数据。
<?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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.