如何让curl命令进入php?

时间:2017-07-27 07:51:42

标签: php curl php-curl

我有这个卷曲命令

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

如何将此转换为php curl请求,记住所有标志。什么是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);
}

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

主要是缺少保存操作(-o $ path):

<?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);
?>