如何将远程图像复制到我的网站目录? [英] How to copy a remote image to my website directory?

查看:204
本文介绍了如何将远程图像复制到我的网站目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布了来自其他网站的图片,我宁愿在我的服务器上安装这些图片,以防他们的服务器突然死亡。假设该文件位于www.www.www / image.gif,如何安全地将其复制到我的目录images?

I post pictures from other websites and I would rather have those on my servers, in case their server dies all of a sudden. Say the file is located at "www.www.www/image.gif", how would I copy it to my directory "images" safely?

我用PHP编写。

谢谢!

推荐答案

以下内容应该有效:

// requires allow_url_fopen
$image = file_get_contents('http://www.url.com/image.jpg');
file_put_contents('/images/image.jpg', $image);

cURL 路线:

$ch = curl_init('http://www.url.com/image.jpg');
$fp = fopen('/images/image.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

这篇关于如何将远程图像复制到我的网站目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆