Copy Image from Remote Server Over HTTPS

北战南征 提交于 2019-12-11 00:37:16

问题


I already find answers how to copy images over HTTP, but when I try to copy images over HTTPS then I get this:

Warning: copy(): SSL operation failed with code 1. OpenSSL Error messages: error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112)

This is code I use:

copy('https://www.metalacmarket.com/product-img/org/JpUSP3KgvgeeikNheRDi4CRg.jpg', IMAGES_PATH.'JpUSP3KgvgeeikNheRDi4CRg.jpg');

Any idea how to get images over HTTPS?


回答1:


You could use cURL.

Here's an example adapted from the basic curl example.

$source = 'https://www.metalacmarket.com/product-img/org/JpUSP3KgvgeeikNheRDi4CRg.jpg';
$target = 'image.jpg';

$ch = curl_init($source);
$fp = fopen($target, "wb");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);


来源:https://stackoverflow.com/questions/19177070/copy-image-from-remote-server-over-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!