$ source是来自需要身份验证/登录的网站的图像的url链接。我能够下载图像,但无法打开下载的图像。我知道图像没有正确下载,因为它要求凭据。我使用CURL下载图像,现在,我不知道代码有什么问题,我还应该添加什么呢?
<?php
$username = $_SESSION["username"];
$password = $_SESSION["password"];
$source = 'https://example.com/sequence.png';
$fp = fopen('C:/image/'.basename($source), 'w');
$ch = curl_init($source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY ) ;
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");// to use for connection
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 1);// content type
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_exec($ch);
fclose($fp);
?>