Last active
June 17, 2024 16:30
-
-
Save oddmario/f15a3b2aeec1938d4ba77737f395b879 to your computer and use it in GitHub Desktop.
A PHP script to give a direct download link for a Google Drive file. (bypasses the Virus scan warning for big files)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// NOTE: Also follow this answer: https://stackoverflow.com/a/2429162/8524395 | |
set_time_limit(0); | |
$requireds = array("fid", "fname"); | |
foreach($requireds as $required) { | |
if( !isset($_GET[$required]) || empty($_GET[$required]) ) { | |
die("error."); | |
} | |
} | |
$gdrive_api_key = ""; // Not necessary to be API key for the account which uploaded the file. The file just have to be enabled for sharing with anyone. | |
$path = "https://www.googleapis.com/drive/v3/files/" . $_GET['fid'] . "/?key=" . $gdrive_api_key . "&alt=media"; | |
$finfo = finfo_open(FILEINFO_MIME_TYPE); | |
header('Content-Type: '.finfo_file($finfo, $path)); | |
$finfo = finfo_open(FILEINFO_MIME_ENCODING); | |
header('Content-Transfer-Encoding: '.finfo_file($finfo, $path)); | |
header('Content-disposition: attachment; filename="'.basename($_GET['fname']).'"'); | |
readfile($path); | |
die(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment