Download the PHP package open-php/google-drive-uploader without Composer
On this page you can find all versions of the php package open-php/google-drive-uploader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download open-php/google-drive-uploader
More information about open-php/google-drive-uploader
Files in open-php/google-drive-uploader
Package google-drive-uploader
Short Description A robust, self-healing Google Drive Uploader for PHP. Features automatic token lifecycle management, smart folder handling, and reliable helpers for embedding images and videos.
License MIT
Homepage https://github.com/mrsandipmandal/google-drive-uploader
Informations about the package google-drive-uploader
Google Drive Uploader Library
A simple, robust PHP library for uploading files to Google Drive. It handles creating folders, setting public permissions, and most importantly, automatic token refreshing and retries (self-healing auth) to handle the dreaded 7-day token expiry for testing apps.
Features
- 📂 Auto-create folders: Automatically creates folders, including nested paths such as
Uploads/Photos. - 🔄 Self-Healing Auth: Automatically catches 401 errors, refreshes tokens using your refresh token, and retries the upload.
- 🌍 Public Links: Option to automatically make uploaded files public and get a web-viewable link.
- ⬇️ Download files: Download Drive files directly to a local path.
- 📦 PSR-4 Compliant: Namespace
Open\GoogleDrive, ready for any Composer project.
Installation
Install via Composer:
Google Cloud Setup
To use this library, you need credentials from the Google Cloud Console.
- Go to Google Cloud Console.
- Create a Project.
- Enable Google Drive API.
- Go to Credentials -> Create Credentials -> OAuth Client ID.
- Application Type: Web Application.
- Redirect URI:
http://localhost/callback.php(or your production URL). - Download the JSON and save it as
credentials.json. - Important: While your OAuth consent screen is in "Testing" mode, refresh tokens for external users can expire after 7 days. Moving the app to production may change this behavior, subject to Google's OAuth policies. The library can refresh access tokens only while Google accepts the stored refresh token.
Keep credentials.json and token.json private. Do not commit them to source control or expose them through a public web directory; restrict filesystem access to the application account.
Usage
1. Initialization
2. First-Time Authentication
If you don't have a token.json yet, you need to authorize the app.
3. Uploading a File
4. Uploading Multiple Files
To upload efficiently (checking folder existence only once):
5. Deleting a File
You can permanently delete a file using its File ID:
6. Renaming a File
You can rename a file using its File ID:
7. Downloading a File
Download a Drive file to a local path. The destination directory must already exist and be writable by PHP.
downloadFile requires Google Drive to provide a download link for the file.
Laravel Integration
This package is framework-agnostic, but can be used in Laravel. The example below shows one way to connect the library's OAuth flow to Laravel routes.
1. Define Routes
In routes/web.php:
[!IMPORTANT] Google Cloud Console Setup You MUST add the full callback URL to your Authorized redirect URIs in the Google Cloud Console.
If your app runs at
http://localhost:8000, add:http://localhost:8000/google/callbackIf your app runs at
http://localhost/myapp/public, add:http://localhost/myapp/public/google/callbackThe URL must match EXACTLY what your Laravel app generates.
2. The Controller
How to Display Files (Blade Example)
Different file types require different HTML tags.
Controller: Pass the id and mimeType to your view.
View (googleFileView.blade.php):
Support
- Issues: GitHub Issues
- Source: GitHub Repository
License
This project is licensed under the MIT License. See LICENSE file for details.
Disclaimer
This independent open-source project is not affiliated with, endorsed by, or sponsored by Google LLC. Google Drive and Google are trademarks of Google LLC.
You are responsible for securing OAuth credentials and tokens, configuring Google Cloud permissions, and complying with Google's applicable terms and policies. Do not expose credentials or tokens in public repositories, client-side code, or public directories.
Author
- Sandip Mandal - GitHub