[英]Save png file locally from a URL in PHP
I have to download a png file and use it for Image Processing in php. 我必须下载一个png文件,并将其用于php中的图像处理。 I want to save this image: /favicon?domain=http://facebook.com/">https://plus.google.com//favicon?domain=http://facebook.com/ into my local folder and perform image processing operations over it. 我想保存以下图像:/favicon?domain=http://facebook.com/">https://plus.google.com//favicon?domain=http://facebook.com/到我的本地文件夹中,在其上执行图像处理操作。
When I am doing this, its working fine: 当我这样做时,它的工作正常:
$url = 'http://s.wordpress.org/about/images/color-blue.png';
$img = 'try1.png';
file_put_contents($img, file_get_contents($url));
but this is not working a file try1.png is getting created of 0kb 但这不起作用,正在创建0kb的try1.png文件
$url = "https://plus.google.com/_/favicon?domain=http://facebook.com/";
$img = 'try1.png';
file_put_contents($img, file_get_contents($url));
Please help. 请帮忙。 Regards, Suyash 问候,Suyash
Please try this: 请尝试以下方法:
<?php
$url = "https://plus.google.com/_/favicon?domain=http://facebook.com/";
$img = 'try1.png';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
file_put_contents($img, $result);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.