-2

I have this curl command

curl -L -O -o ' .$path.' -J "https://drive.google.com/uc?export=download&id='.$id.'"

How would I transform this into php curl request keeping in mind all the flags. what are the equivalents in php

Here is what I have so far

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://drive.google.com/uc?export=download&id='.$id.'");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
  • What is the issue with what you got? You've already covered the `-L` flag by setting `CURLOPT_FOLLOWLOCATION`. The other flags are quite irrelevant since they are letting curl know what to do with the response (save it to file etc), which you don't do in PHP. Just take the result and do what you want with it instead. – M. Eriksson Jul 27 '17 at 08:03

2 Answers2

0
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://drive.google.com/uc?export=download&id=123"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
0

mainly the save action (-o $path) is missing:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://drive.google.com/uc?export=download&id='.$id.'");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

file_put_contents($path, $result);
?>
Ivo P
  • 1,722
  • 1
  • 7
  • 18