PHP-直接将图片从URL复制到我的服务器 [英] PHP - Copy image to my server direct from URL

查看:406
本文介绍了PHP-直接将图片从URL复制到我的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
使用php从php网址保存图像

Possible Duplicate:
save image from php url using php

我想要以下的PHP代码.

I want to have PHP code for following.

假设我有一个图片网址,例如 http: //www.google.co.in/intl/zh_CN/images/srpr/logo1w.png

Suppose I have one image URL, for example, http://www.google.co.in/intl/en_com/images/srpr/logo1w.png

如果我运行一个脚本,该图像将被复制并放在服务器上具有777权限的文件夹中.

If I run one script, this image will be copied and put on my server within folder having 777 rights.

有可能吗?如果可以,请给我指导吗?

Is it possible? If yea, can you please give direction for same?

谢谢

伊恩

推荐答案

两种方式(如果您使用的是PHP5(或更高版本)

Two ways, if you're using PHP5 (or higher)

copy('http://www.google.co.in/intl/en_com/images/srpr/logo1w.png', '/tmp/file.png');

如果没有,请使用 file_get_contents

//Get the file
$content = file_get_contents("http://www.google.co.in/intl/en_com/images/srpr/logo1w.png");
//Store in the filesystem.
$fp = fopen("/location/to/save/image.png", "w");
fwrite($fp, $content);
fclose($fp);

来自此SO帖子

这篇关于PHP-直接将图片从URL复制到我的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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