php實現批量下載百度雲端硬碟檔案例子分享_php執行個體

來源:互聯網
上載者:User

百度開放雲PhpSDK下載地址:http://developer.baidu.com/wiki/index.php?title=%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3%E9%A6%96%E9%A1%B5/web%E5%BA%94%E7%94%A8%E6%8E%A5%E5%85%A5/SDK

執行個體代碼:

複製代碼 代碼如下:

<?php
/**
 * Author: hankcs
 * Date  : 14-3-29
 * Time  : 下午10:29
 */
ini_set("max_execution_time", 36000);
require_once '../bcs.class.php';
require_once '../krumo/class.krumo.php';
$host = 'bcs.duapp.com';
$ak = '你的公開金鑰';
$sk = '你的私密金鑰';
$bucket = '要下載的bucket名稱';
$baidu_bcs = new BaiduBCS ( $ak, $sk, $host );

$response = json_decode($baidu_bcs->list_object ( $bucket, array('start' => 0,'limit' => 1024,) )->body);
$downloaded_size = 0;
while($downloaded_size < $response->object_total)
{
    krumo($response);
    // 下載它們
    foreach($response->object_list as $object)
    {
        if(!$object->is_dir)
        {
            mk_dir('.'.$object->parent_dir);
            $result = $baidu_bcs->get_object ( $bucket, $object->object, array ("fileWriteTo" => '.'.$object->object ) );
        }
    }
    $downloaded_size += count($response->object_list);
    $response = json_decode($baidu_bcs->list_object ( $bucket, array('start' => $downloaded_size,'limit' => 1024,) )->body);
}

function mk_dir($dir, $mode = 0755)
{
    if (is_dir($dir) || @mkdir($dir,$mode)) return true;
    if (!mk_dir(dirname($dir),$mode)) return false;
    return @mkdir($dir,$mode);
}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.