Answer the question
In order to leave comments, you need to log in
Curl download file?
Hello.
What is the situation, you need to download the file from i.disk.
I took the ready-made nixsolutions/yandex-php-library library, it works.
I change the token to another, with exactly the same settings, authorization fails. Super support for Yandex, just unsubscribed, saying "we do not guarantee the ability of our services";)
Well ....
I start writing my class, it works, BUT the method of downloading the picture does not work.
$url = 'https://cloud-api.yandex.net/v1/disk/resources/download?path=' . urlencode($YApath);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth ' . $this->token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$res = curl_exec($ch);
curl_close($ch);*/
// echo $res;
$res = json_decode($res);
$file_name = $localPath;
var_dump($file_name);
var_dump($localPath);
var_dump($res->href);
$file = fopen($file_name, 'w');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $res->href);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth ' . $this->token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FILE, $file);
$res = curl_exec($ch);
curl_close($ch);
fclose($file);
var_dump($res);
Answer the question
In order to leave comments, you need to log in
Try using file_get_contents instead of cuRL
$context = stream_context_create([
"ssl" => [
"verify_peer" => false,
"verify_peer_name" => false,
],
]);
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
echo file_get_contents($link, false, $context);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question