PHP code example of tes / laravel-google-drive-storage

1. Go to this page and download the library: Download tes/laravel-google-drive-storage 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/ */

    

tes / laravel-google-drive-storage example snippets


use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$file = $request->file('upload'); // Assuming this comes from a form

$response = GoogleDriveService::uploadFile($file);
echo "File uploaded with ID: " . $response->id;

use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$folderName = 'New Folder';
$response = GoogleDriveService::createFolder($folderName);
echo "Folder created with ID: " . $response['folderId'];

use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$searchName = 'example';
$files = GoogleDriveService::search($searchName, 'all'); // Can be 'files', 'folders', or 'all'

foreach ($files as $file) {
    echo "Found file with ID: " . $file['id'] . " and name: " . $file['name'] . "\n";
}

use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$folderId = 'your_folder_id';
$files = GoogleDriveService::listFilesInFolder($folderId);

foreach ($files as $file) {
    echo "File in folder with ID: " . $file['id'] . " and name: " . $file['name'] . "\n";
}

use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$fileId = 'your_file_id';
$metadata = GoogleDriveService::getFileMetadata($fileId);

echo "File metadata:\n";
echo "ID: " . $metadata['id'] . "\n";
echo "Name: " . $metadata['name'] . "\n";
echo "MIME Type: " . $metadata['mimeType'] . "\n";
echo "Size: " . $metadata['size'] . "\n";
echo "Created Time: " . $metadata['createdTime'] . "\n";
echo "Modified Time: " . $metadata['modifiedTime'] . "\n";

use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$fileId = 'your_file_id';
$newName = 'Updated File Name';
$response = GoogleDriveService::updateFileMetadata($fileId, $newName);

echo "File updated with ID: " . $response['id'] . " and new name: " . $response['name'];

use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$path = 'path/to/your/file/on/drive';
$response = GoogleDriveService::download($path); // you got it!!

use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$path = 'path/to/your/file/on/drive';
$url = GoogleDriveService::url($path);

echo "File URL: " . $url; // Like This Format: https://drive.google.com/file/d/1jGhj2nX2MNbH5VPwe8SqTKSUu0U-S-VX/view?usp=sharing

use Tes\LaravelGoogleDriveStorage\GoogleDriveService;

$path = 'path/to/your/file/on/drive';
$response = GoogleDriveService::delete($path);

if ($response) {
    echo "File deleted successfully.";
} else {
    echo "Failed to delete file.";
}