通过HTTP从远程服务器复制映像 [英] Copy Image from Remote Server Over HTTP

查看:275
本文介绍了通过HTTP从远程服务器复制映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种简单的方法使用PHP从远程服务器导入/复制图像到本地文件夹。我没有FTP访问服务器,但所有远程图像都可以通过HTTP访问(即 http:// www .mydomain.com / myimage.jpg )。

I am looking for a simple way to import/copy images from remote server to a local folder using PHP. I have no FTP access to the server, but all remote images can be accessed via HTTP (i.e. http://www.mydomain.com/myimage.jpg).

使用示例:用户希望将图像添加到他的个人资料中。该图片已存在于网络上,用户提供了直接网址。

Example use: A user wishes to add an image to his profile. The image already exists on the web and the user provides with a direct URL. I do not wish to hotlink the image but to import and serve from my domain.

推荐答案

如果您有PHP5和HTTP流在您的服务器上启用了封装,将其复制到本地文件非常简单:

If you have PHP5 and the HTTP stream wrapper enabled on your server, it's incredibly simple to copy it to a local file:

copy('http://somedomain.com/file.jpeg', '/tmp/file.jpeg');

这将照顾所需的任何流水线等。如果你需要提供一些HTTP参数,你可以提供第三个stream context参数。

This will take care of any pipelining etc. that's needed. If you need to provide some HTTP parameters there is a third 'stream context' parameter you can provide.

这篇关于通过HTTP从远程服务器复制映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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