Get direct download link from any Google Drive sharable link. So you don't need to open Google Drive webpage to download the file.
Also it can help you to embed assets anywhere because the link you will extract from this library will directly download the assets without going to any middle-page.
It's very easy to use with composer
. Run the following command -
composer require shahariaazam/gdrive-direct-download-link
It will add the package shahariaazam/gdrive-direct-download-link
in your project.
<?php
use ShahariaAzam\GDriveLinkExtractor\GoogleDriveLink;
require "vendor/autoload.php";
$sharableURL = 'GOOGLE_DRIVE_SHARABLE_LINK';
$downloadLink = GoogleDriveLink::get($sharableURL);
It's a very tiny library. But if you don't want to install it. Here is the function that you can use.
<?php
function downloadLink($sharableLink)
{
return preg_replace("/\/file\/d\/(.+)\/(.+)/", "/uc?export=download&id=$1", $sharableLink);
}
echo downloadLink('https://drive.google.com/file/d/FAKE_FILE_ID/view?usp=sharing');
Yes, it's that simple.
Note: I just made this as a composer package because I wanted to make it testable for future compatibility