简体   繁体   English

从wamp服务器下载图像,并使用php将其保存在我的文件夹中

[英]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.

相关问题 PHP代码可从文件夹中下载.pdf和.docx文件,并将其存储在Wamp Server中 - PHP code to download .pdf & .docx files from folder stored my Wamp Server 任何从网上下载图像并将其保存在我的服务器中的php函数? - Any php function to download an image from web and save it in my server? 如何从WAMP服务器下载图像文件? - How to download an image file from WAMP server? 使用图像URL和PHP将图像从远程服务器上传/下载/保存到本地服务器? - Upload/download/save image to a local server from a remote server using an Image URL and PHP? 使用php在我的服务器上下载图像 - Download image on my server using php 如何使用ftp从服务器下载文件以及如何将该文件保存在本地文件夹中 - How to download a file from server using ftp and how to save that file in my local folder 如何在 php 中创建文件夹并将图像保存在我的服务器上? - How can a create a folder and save a image on my server in php? 无法使用PHP从我的文件夹下载文件 - Unable to download my files from my folder using PHP 使用PHP在服务器上的文件夹中打开图像并调整其大小,然后将其保存回来 - open and resize an image from a folder on the server in PHP and save it back My.php 文件未在 WAMP 服务器上运行,它正在尝试保存文件 - My .php files not running on WAMP Server, it is trying to save the file instead
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM