好吧,这是我在bash中的cURL脚本,可以正常工作!
#!/bin/bash
fileid="1yvklOFopnep8twiqAQecmMUoAbQVzU0r"
filename="MyFile.mp4"
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}
但是,我试图将其重写为一个简单的PHP脚本,尽管它似乎无法正常工作;代码如下:
<?php
define('FILENAME', 'MyFile.mp4');
define('FILE_ID', '1yvklOFopnep8twiqAQecmMUoAbQVzU0r');
$GlobalFileHandle = null;
function get_confirm($id)
{
$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_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
preg_match_all("/confirm=([0-9A-Za-z]+)&/", $result, $output_array);
return $output_array[1][0];
}
function get_file($id, $confirm)
{
global $GlobalFileHandle;
$GlobalFileHandle = fopen(FILENAME, 'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://drive.google.com/uc?export=download&confirm='.$confirm.'&id='.$id);
curl_setopt($ch, CURLOPT_FILE, $GlobalFileHandle);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'curlWriteFile');
curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
fclose($GlobalFileHandle);
}
但是,文件似乎没有被下载 &'我的文件.mp4仍然为空?
一只斗牛犬
慕桂英4014372