PHP保存图像文件 [英] PHP save image file
本文介绍了PHP保存图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
从PHP URL保存图像
Possible Duplicate:
Saving image from PHP URL
I have an image as a url link from the 3rd party web thumb site (IE http://images.websnapr.com/?size=size&key=Y64Q44QLt12u&url=http://google.com) What I would like to do is run a script that takes the image and saves it in a directory on my server using php. How to do this? would I use File Write?
推荐答案
无需像其他人建议的那样创建GD资源.
No need to create a GD resource, as someone else suggested.
$input = 'http://images.websnapr.com/?size=size&key=Y64Q44QLt12u&url=http://google.com';
$output = 'google.com.jpg';
file_put_contents($output, file_get_contents($input));
注意:仅当您设置为允许fopen访问URL时,此解决方案才有效.如果上述解决方案不起作用,则必须使用cURL.
Note: this solution only works if you're setup to allow fopen access to URLs. If the solution above doesn't work, you'll have to use cURL.
这篇关于PHP保存图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文