使用PHP将文件上传到Google云端硬盘

I tried to upload a file to Google Drive but i couldn't do it.

I tried with the google-api-php-client but this API is not stable, missing functions... and when i follow the doc, they don't work because $client->getAuth()->authenticate(code) doesn't exit.

And now the API is changing. I use the v1-master.

After i try with curl but i have an error : Error String:Couldn't resolve host 'account.google.com'.

Please, someone have a solution for upload a file to Google Drive with php ?

Thanks

Hey you could try this snippet.. [Credits to Ben Servoz ]

/*******************************************************************************
 * file:        google_drive_upload.php
 * author:      ben servoz
 * description: script to upload files to Google Drive
 * notes:       instructions at http://ben.akrin.com/?p=2080
*******************************************************************************/

// configuration
//   google oauth
$client_id = "your client ID here" ;
$client_secret = "your client secret here" ;
$refresh_token = "your refresh token here" ;
//   chunk size (this HAS to be a multiple of 256KB so only change the last integer)
$chunk_size = 256 * 1024 * 400 ; // this will upload files 100MB at a time
//   miscellaneous
$verbose = true ;   
$file_binary = "/usr/bin/file" ; // used for detecting mime type
//   md5
$check_md5_after_upload = true ;
$md5sum_binary = "/usr/bin/md5sum" ;


// todo: grant URL follow thingy if it hasn't been done already

if( count($argv)<2 || count($argv)>3 || in_array("-h", $argv) || in_array("--help", $argv) ) {
    echo "usage: {$argv[0]} <file_name> [folder_id]

    where <file_name> is the full path to the file that you want to upload to Google Drive.
      and [folder_id] is the the folder where you want to upload the file (optional, defaults to root)

" ;
    exit( 1 ) ;
}

$file_name = $argv[1] ;
if( !file_exists($file_name) ) {
    echo "ERROR: {$file_name} is not found on the filesystem
" ;
    exit( 1 ) ;
}