簡體   English   中英

從PHP中的URL在本地保存png文件

[英]Save png file locally from a URL in PHP

我必須下載一個png文件,並將其用於php中的圖像處理。 我想保存以下圖像:/favicon?domain=http://facebook.com/">https://plus.google.com//favicon?domain=http://facebook.com/到我的本地文件夾中,在其上執行圖像處理操作。

當我這樣做時,它的工作正常:

$url = 'http://s.wordpress.org/about/images/color-blue.png';
$img = 'try1.png';
file_put_contents($img, file_get_contents($url));

但這不起作用,正在創建0kb的try1.png文件

$url = "https://plus.google.com/_/favicon?domain=http://facebook.com/";
$img = 'try1.png';
file_put_contents($img, file_get_contents($url));

請幫忙。 問候,Suyash

請嘗試以下方法:

<?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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM