0

I have share link drive and I want to get direct link download drive.

For example, I have:

Link: https://drive.google.com/file/d/1kKaAZqkZJjdw_0kZM908Bx_uT7vD7yyW/view?usp=sharing

The direct link download I want is https://doc-0k-1k-docs.googleusercontent.com/docs/... of this link share (you can see in image -> Response Headers >> Location).

I have read this post: generate custom direct download link for google drive link but still can not get direct link download.

Here is my update code:

<?php
$urlShare = 'https://drive.google.com/file/d/1kKaAZqkZJjdw_0kZM908Bx_uT7vD7yyW/view?usp=sharing';
$urlDown = 'https://drive.google.com/u/0/uc?id=1kKaAZqkZJjdw_0kZM908Bx_uT7vD7yyW&export=download';
$id = '1kKaAZqkZJjdw_0kZM908Bx_uT7vD7yyW';

$ch = curl_init('https://drive.google.com/u/0/uc?id='.$id.'&export=download');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, []);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Language: en-US,en;q=0.9',
    'Accept-Encoding: gzip, deflate, br',
    'Content-Type: application/x-www-form-urlencoded',
    'Content-Length: 0'
));
$result = curl_exec($ch);

$object = json_decode(str_replace(')]}\'', '', $result));

exit(header('Location: '. $object->downloadUrl));

I can not get anything from this code.

I have check Request URL when download file and see that the URL have &uuid=0f70a2fc-5777-4530-abac-f28bedfa779b&at=AKKF8vxFN9zAjfzc15KmDmeAfuBL:1686540753261 but not know anything about this (I have research but still not understand it). Is this need for insert into curl_init() too?

Please help me if I have miss anything. Also if possible to get direct link download using javascript code (I want to use js code or php code)?

enter image description here

The LB
  • 56
  • 4

0 Answers0