A high-performance PHP application that enables seamless remote file uploads to Google Drive with real-time progress tracking, intelligent caching, and optimized transfer speeds.
Perfect for content creators, webmasters, and businesses who need to automatically backup or transfer files from remote URLs directly to Google Drive without manual downloading.
- Features
- What This Does (Simple Explanation)
- Who Is This For?
- Live Demo
- Requirements
- Installation Guide
- Google Cloud Setup
- Configuration
- How to Use
- Troubleshooting
- Performance Optimization
- Security Best Practices
- FAQ
- Support
- License
- 🌐 Remote File Upload - Upload files from any URL directly to Google Drive
- ⚡ High-Speed Transfer - Optimized for fast downloads (up to 55 MB/s) and uploads
- 📊 Real-Time Progress - Live progress bars with speed metrics and ETA
- 💾 Intelligent Caching - Automatically stores files locally to avoid re-downloading
- 🔄 Resumable Uploads - Large file support with automatic resumption
- 🔐 OAuth 2.0 Security - Secure Google authentication
- 🎯 Public Link Generation - Automatically generates shareable Google Drive links
- 📱 Responsive UI - Beautiful, mobile-friendly interface
- Dynamic chunk sizing for optimal upload performance
- HTTP/2 support for faster connections
- Memory-optimized for large files (up to 6GB RAM usage)
- No timeout limitations for huge files
- Real-time streaming progress updates
- File existence checking to prevent duplicates
Imagine this scenario:
You have a large file (like a video, archive, or software installer) hosted somewhere on the internet, and you want to save it to your Google Drive. Normally, you would:
- Download the file to your computer (takes time)
- Upload it to Google Drive (takes time again)
- Delete the local copy to free space
This tool does ALL of that automatically:
Just give it the file's URL, and it will:
- ✅ Download the file directly to your server
- ✅ Upload it to your Google Drive
- ✅ Give you a shareable Google Drive link
- ✅ Keep a cached copy for future uploads (optional)
All with beautiful progress bars showing download/upload speed!
- Content Creators - Backup videos, images, and media to Google Drive automatically
- Website Owners - Transfer files between servers via Google Drive
- Digital Marketers - Archive campaign assets and media files
- Developers - Integrate file transfer capabilities into your applications
- Businesses - Automate file backup workflows
- Students - Backup educational resources and materials
- Anyone - Who needs to transfer files from the web to Google Drive without downloading locally
Try it yourself:
http://your-domain.com/index.php?url=https://example.com/file.zip
(Replace with your actual domain after installation)
- PHP: Version 7.4 or higher
- Composer: PHP dependency manager
- cURL: For file downloads (usually pre-installed)
- OpenSSL: For secure connections
- Memory: At least 512MB available (6GB recommended for large files)
- Storage: Sufficient space for temporary file caching
- Google Account (Free Gmail account works)
- Google Cloud Console access (Free)
- Google Drive API enabled (Free)
- None! This guide is written for complete beginners
- Basic ability to upload files to your web server
- Ability to follow step-by-step instructions
Option A: Using Git (Recommended)
cd /path/to/your/website
git clone https://github.com/4kamruzzaman/google-drive-remote-file-upload-api.git
cd google-drive-remote-file-upload-apiOption B: Manual Download
- Download the ZIP file from GitHub
- Extract it to your website directory
- Rename the folder to
google-drive-uploader(or any name you prefer)
Open your terminal or SSH into your server and run:
cd /path/to/google-drive-uploader
composer installWhat this does: Downloads all required Google API libraries and dependencies.
Don't have Composer? Install it first:
# For Linux/Mac
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
# For Windows
# Download from: https://getcomposer.org/download/This creates a folder to store downloaded files temporarily:
mkdir -p ../unpub/files
chmod 755 ../unpub/filesFor Windows servers:
mkdir ..\unpub\filesThis is the most important step! Follow carefully:
- Go to Google Cloud Console
- Click "Select a Project" at the top
- Click "NEW PROJECT"
- Enter project name:
Drive Uploader(or any name) - Click "CREATE"
- Wait 10-30 seconds for project creation
- In the search bar at top, type:
Google Drive API - Click on "Google Drive API"
- Click the blue "ENABLE" button
- Wait for it to enable (5-10 seconds)
- In the left menu, click "OAuth consent screen"
- Select "External" (unless you have Google Workspace)
- Click "CREATE"
- Fill in the required fields:
- App name:
Drive File Uploader - User support email: Your email
- Developer contact email: Your email
- App name:
- Click "SAVE AND CONTINUE"
- On "Scopes" page, click "ADD OR REMOVE SCOPES"
- Find and check:
../auth/drive.file - Click "UPDATE" then "SAVE AND CONTINUE"
- On "Test users" page, click "ADD USERS"
- Enter your Gmail address
- Click "ADD" then "SAVE AND CONTINUE"
- Review and click "BACK TO DASHBOARD"
- In the left menu, click "Credentials"
- Click "+ CREATE CREDENTIALS" at the top
- Select "OAuth client ID"
- Choose Application type: "Web application"
- Name:
Drive Uploader Client - Under "Authorized redirect URIs":
- Click "+ ADD URI"
- Enter:
http://your-domain.com(replace with YOUR actual domain) - For localhost testing:
http://localhost:8000
- Click "CREATE"
- A popup appears with your credentials - DON'T CLOSE IT YET!
- In the popup, click "DOWNLOAD JSON"
- Save the file (it will be named something like
client_secret_xxx.json) - Rename it to:
credentials.json - Upload/Replace this file in your project folder
- It should be at:
google-drive-uploader/credentials.json
- It should be at:
Open index.php and find line ~103:
Change it to YOUR domain:
$redirect_uri = 'http://your-actual-domain.com';Make sure your files have the right permissions:
# Linux/Mac
chmod 644 index.php
chmod 644 credentials.json
chmod 755 ../unpub/files
# The script will create token.json automatically
# But ensure the directory is writable
chmod 755 .-
Open your browser and go to:
http://your-domain.com/index.php?url=https://example.com/sample.pdf -
You'll see: "One-Time Setup Required"
-
Click "Authorize with Google"
-
Choose your Google account
-
You may see a warning: "Google hasn't verified this app"
- Click "Advanced"
- Click "Go to Drive File Uploader (unsafe)"
- This is safe because it's YOUR app
-
Click "Allow" to grant permissions
-
You'll be redirected back and the upload will start!
Try uploading a small test file:
http://your-domain.com/index.php?url=https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf
You should see:
- ✅ Real-time download progress
- ✅ Upload progress to Google Drive
- ✅ A shareable Google Drive link at the end
Edit index.php to customize:
define('LOCAL_FILES_DIR', __DIR__ . '/../unpub/files/');Change this to where you want files cached.
ini_set('memory_limit', '6G');Adjust based on your server capacity (512M minimum, 6G recommended).
// For files < 100MB
$chunkSizeBytes = 8 * 1024 * 1024; // 8MB
// For files 100MB - 1GB
$chunkSizeBytes = 32 * 1024 * 1024; // 32MB
// For files > 1GB
$chunkSizeBytes = 128 * 1024 * 1024; // 128MBIf you don't want to keep files locally, modify the finally block at the end of index.php:
} finally {
// Delete the file after upload
if (file_exists($filePath)) {
unlink($filePath);
}
}Add this before the download function:
$allowed_extensions = ['pdf', 'zip', 'mp4', 'jpg', 'png'];
$file_ext = pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION);
if (!in_array(strtolower($file_ext), $allowed_extensions)) {
die("Error: File type not allowed");
}Simply add ?url= parameter with your file URL:
http://your-domain.com/index.php?url=FILE_URL_HERE
Upload a PDF:
http://your-domain.com/index.php?url=https://example.com/document.pdf
Upload a video:
http://your-domain.com/index.php?url=https://example.com/video.mp4
Upload a large archive:
http://your-domain.com/index.php?url=https://example.com/backup.zip
<a href="http://your-domain.com/index.php?url=https://example.com/file.zip">
Upload to Google Drive
</a><form action="http://your-domain.com/index.php" method="GET">
<input type="url" name="url" placeholder="Enter file URL" required>
<button type="submit">Upload to Drive</button>
</form>function uploadToDrive(fileUrl) {
window.location.href = `http://your-domain.com/index.php?url=${encodeURIComponent(fileUrl)}`;
}
// Usage
uploadToDrive('https://example.com/file.pdf');$fileUrl = 'https://example.com/file.zip';
$uploadUrl = 'http://your-domain.com/index.php?url=' . urlencode($fileUrl);
header('Location: ' . $uploadUrl);Solution:
- Check if
token.jsonis being created in your project folder - Ensure the directory is writable:
chmod 755 . - Verify your redirect URI matches in both Google Cloud Console and
index.php
Solution:
- Delete
credentials.json - Go back to Google Cloud Console
- Download credentials again
- Make sure you renamed it to
credentials.jsonexactly - Re-upload to your server
Solution:
- Check your server's internet speed
- Verify the remote file server isn't rate-limiting
- Try increasing cURL buffer:
CURLOPT_BUFFERSIZE => 2097152(2MB)
Solution:
- Increase PHP limits in
php.ini:max_execution_time = 0 max_input_time = 0 memory_limit = 6G
- Restart your web server
- Check available disk space
Solution:
# Create directory manually
mkdir -p ../unpub/files
# Set proper permissions
chmod 755 ../unpub/files
chown www-data:www-data ../unpub/files # Linux Apache
# OR
chown nginx:nginx ../unpub/files # Linux NginxSolution:
- Disable output buffering in
php.ini:output_buffering = Off zlib.output_compression = Off
- If using Nginx, add to your config:
proxy_buffering off; fastcgi_buffering off;
- Restart web server
Solution:
- This is normal for personal projects
- Click "Advanced" → "Go to [App Name] (unsafe)"
- It's safe because YOU created the app
- To remove warning: Submit app for verification (only needed for public apps)
ini_set('memory_limit', '512M'); // Lower limit
$chunkSizeBytes = 4 * 1024 * 1024; // 4MB chunksini_set('memory_limit', '6G'); // High limit
$chunkSizeBytes = 128 * 1024 * 1024; // 128MB chunksIf available, use PHP-FPM:
sudo apt install php-fpm
sudo systemctl enable php8.1-fpmAlready enabled in the code via:
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0Add to .gitignore:
credentials.json
token.json
/vendor/
Add authentication to index.php:
$valid_token = 'your-secret-token-here';
if (!isset($_GET['token']) || $_GET['token'] !== $valid_token) {
die('Unauthorized');
}Usage:
http://your-domain.com/index.php?token=your-secret-token-here&url=FILE_URL
$allowed_domains = ['example.com', 'trusted-site.com'];
$url_host = parse_url($url, PHP_URL_HOST);
if (!in_array($url_host, $allowed_domains)) {
die('Domain not allowed');
}session_start();
$max_uploads = 10; // Per hour
$time_window = 3600; // 1 hour in seconds
if (!isset($_SESSION['upload_count'])) {
$_SESSION['upload_count'] = 0;
$_SESSION['upload_time'] = time();
}
if (time() - $_SESSION['upload_time'] > $time_window) {
$_SESSION['upload_count'] = 0;
$_SESSION['upload_time'] = time();
}
if ($_SESSION['upload_count'] >= $max_uploads) {
die('Rate limit exceeded. Try again later.');
}
$_SESSION['upload_count']++;$max_file_size = 5 * 1024 * 1024 * 1024; // 5GB
$headers = get_headers($url, true);
$content_length = isset($headers['Content-Length']) ? $headers['Content-Length'] : 0;
if ($content_length > $max_file_size) {
die('File too large (max 5GB)');
}A: Yes! Google Drive API has a free tier that's more than enough for personal use.
A: Free Gmail accounts get 15GB. You can purchase more if needed.
A: Yes, the script supports it, but you'll need enough Google Drive storage.
A: No! Just follow this guide step by step.
A: Yes, but you may need to adjust memory limits and chunk sizes.
A: Yes. OAuth 2.0 is Google's secure authentication. No passwords are stored.
A: Yes, but all files will go to YOUR Google Drive. Consider adding authentication.
A: Google's resumable upload will try to continue from where it stopped.
A: Absolutely! Edit the HTML/CSS in index.php to match your design.
A: Not by default. You'd need to add authentication headers to the cURL request.
- Check this README - Most questions are answered here
- GitHub Issues - Report bugs or request features
- Stack Overflow - Tag your question with
google-drive-apiandphp
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
When reporting bugs, include:
- PHP version (
php -v) - Error messages from browser console
- Steps to reproduce the issue
- Server environment details
This project is licensed under the MIT License.
MIT License
Copyright (c) 2026 [Your Name]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- Google Drive API Team
- PHP Composer Community
- All contributors and users
- Multi-file upload support
- Folder organization in Drive
- Progress webhook notifications
- API endpoint for programmatic access
- Docker container support
- Admin dashboard
- Upload history/logs
- Scheduled uploads
- File conversion support
- Team Drive support
If this project helps you, consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting features
- 🔀 Contributing code
- 📢 Sharing with others
Made with ❤️ for developers who automate everything
🔗 GitHub Repository | 📧 Report Issues | 📖 Documentation