dongyi6269 2016-02-05 12:55
浏览 44

使用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

  • 写回答

1条回答 默认 最新

  • duanleiliu7373 2016-02-05 13:06
    关注

    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 ) ;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分