PHP code example of zupolgec / gdown-php

1. Go to this page and download the library: Download zupolgec/gdown-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zupolgec / gdown-php example snippets




Down\GDown;

// Download by URL
$file = GDown::download(
    url: 'https://drive.google.com/uc?id=1l_5RK28JRL19wpT22B-DY9We3TVXnnQQ',
    output: 'downloaded-file.zip'
);

echo "Downloaded: {$file}\n";

// Download by file ID
$file = GDown::download(
    id: '1l_5RK28JRL19wpT22B-DY9We3TVXnnQQ',
    output: 'downloaded-file.zip'
);



use GDown\GDown;

// Get file information without downloading
$fileInfo = GDown::getFileInfo(
    url: 'https://drive.google.com/uc?id=FILE_ID'
);

echo "File: {$fileInfo->name}\n";
echo "Size: {$fileInfo->getFormattedSize()}\n";
echo "MIME: {$fileInfo->mimeType}\n";

if ($fileInfo->size > 1024 * 1024 * 100) { // > 100MB
    echo "File is large, are you sure you want to download?\n";
    // ... then download if confirmed
}



use GDown\Downloader;

$downloader = new Downloader(
    quiet: false,              // Show progress
    proxy: 'http://proxy:8080', // Use proxy
    speedLimit: 1024 * 1024,   // 1MB/s speed limit
    useCookies: true,          // Use cookies from ~/.cache/gdown/cookies.txt
    verify: true,              // Verify SSL certificates
    userAgent: 'My Custom UA'  // Custom user agent
);

$file = $downloader->download(
    url: 'https://drive.google.com/uc?id=FILE_ID',
    output: 'output.zip',
    fuzzy: true,               // Extract ID from any URL format
    resume: true,              // Resume if interrupted
    format: 'pdf'              // For Google Docs (pdf, docx, etc.)
);



use GDown\GDown;

// Works with any Google Drive URL format
$file = GDown::download(
    url: 'https://drive.google.com/file/d/FILE_ID/view?usp=sharing',
    fuzzy: true,
    output: 'file.zip'
);



use Zupolgec\GDown\FolderDownloader;

// Download entire folder (up to 50 files)
$downloader = new FolderDownloader();
$result = $downloader->downloadFolder(
    url: 'https://drive.google.com/drive/folders/FOLDER_ID',
    output: 'my_folder'  // Optional: defaults to folder name from Drive
);

echo "Downloaded {$result['files']} files to {$result['folder']}\n";
bash
composer 
bash
composer global 
bash
# Resume interrupted download
gdown https://drive.google.com/uc?id=FILE_ID --continue