title: Upload large file to google drive with PHP Client Library
body: <p>I am trying to use the Google Drive API via their PHP Client Library to upload a large file. Currently it fails because the only method seemingly available is the "simple" upload method. Unfortunately that requires you to load the entire file as data and it hits my php memory limit. I would like to know if it is possible and see an example of how it is done. I know there is a method for resumable and chuncked uploads, but there is no documentation on how to use it.</p>
  
  <pre><code>&lt;?php
  require_once 'google-api-php-client/src/Google_Client.php';
  require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
  
  $client = new Google_Client();
  // Get your credentials from the APIs Console
  $client-&gt;setClientId('YOUR_CLIENT_ID');
  $client-&gt;setClientSecret('YOUR_CLIENT_SECRET');
  $client-&gt;setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
  $client-&gt;setScopes(array('https://www.googleapis.com/auth/drive'));
  
  $service = new Google_DriveService($client);
  
  $authUrl = $client-&gt;createAuthUrl();
  
  //Request authorization
  print "Please visit:\n$authUrl\n\n";
  print "Please enter the auth code:\n";
  $authCode = trim(fgets(STDIN));
  
  // Exchange authorization code for access token
  $accessToken = $client-&gt;authenticate($authCode);
  $client-&gt;setAccessToken($accessToken);
  
  //Insert a file
  $file = new Google_DriveFile();
  $file-&gt;setTitle('My document');
  $file-&gt;setDescription('A test document');
  $file-&gt;setMimeType('text/plain');
  
  $data = file_get_contents('document.txt');
  
  $createdFile = $service-&gt;files-&gt;insert($file, array(
        'data' =&gt; $data,
        'mimeType' =&gt; 'text/plain',
      ));
  
  print_r($createdFile);
  ?&gt;
  </code></pre>