Advertisement
Guest User

direct

a guest
Feb 21st, 2019
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. <?php
  2.     define("googledrive_key", "AIzaSyD739-eb6NzS_KbVJq1K8ZAxnrMfkIqPyw");
  3.    
  4.     function generateLink($DriveID, $direct=FALSE) {
  5.         if(filter_var($DriveID, FILTER_VALIDATE_URL)) $DriveID = $this->get_driveid_from_url($DriveID);
  6.         $ch = curl_init("https://drive.google.com/uc?id=$DriveID&authuser=0&export=download");
  7.         curl_setopt_array($ch, array(
  8.             CURLOPT_CUSTOMREQUEST => 'POST',
  9.             CURLOPT_SSL_VERIFYPEER => false,
  10.             CURLOPT_POSTFIELDS => [],
  11.             CURLOPT_RETURNTRANSFER => true,
  12.             CURLOPT_ENCODING => 'gzip,deflate',
  13.             CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
  14.             CURLOPT_HTTPHEADER => [
  15.                 'accept-encoding: gzip, deflate, br',
  16.                 'content-length: 0',
  17.                 'content-type: application/x-www-form-urlencoded;charset=UTF-8',
  18.                 'origin: https://drive.google.com',
  19.                 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
  20.                 'x-client-data: CKG1yQEIkbbJAQiitskBCMS2yQEIqZ3KAQioo8oBGLeYygE=',
  21.                 'x-drive-first-party: DriveWebUi',
  22.                 'x-json-requested: true'
  23.             ]
  24.         ));
  25.         $response = curl_exec($ch);
  26.         $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  27.         curl_close($ch);
  28.         if($response_code == '200') { // Jika response status OK
  29.             $object = json_decode(str_replace(')]}\'', '', $response));
  30.             if(isset($object->downloadUrl)) {
  31.                 if($direct) return header("Location:$object->downloadUrl");
  32.                 return  $object->downloadUrl;
  33.             }
  34.         } else {
  35.             return $response_code;
  36.         }
  37.     }
  38.    
  39.    
  40.    
  41.         function name($gid, $req) {
  42.         $hasil = file_get_contents('https://content.googleapis.com/drive/v2/files/'.$gid.'?key='.googledrive_key);
  43.         $hasil = json_decode($hasil, true);
  44.         return $hasil[$req];
  45.     }
  46.    
  47. $id = $_GET['id'];
  48.  
  49. $link = generateLink($id, false, 0);
  50. $tod = generateLink($id, false, 1);
  51. if($tod == 200){
  52. $nama = name($id, 'title');
  53. $type = name($id, 'mimeType');
  54.  
  55. echo $link.'<br/>';
  56. echo $nama ;
  57. }else{
  58.     echo $link;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement