Example of batch downloading Baidu cloud disk files using php

Source: Internet
Author: User
This article uses Baidu open cloud PHPSDK to download Baidu cloud disk files in batches. For more information, see. Baidu Cloud

Open Cloud PhpSDK Baidu: http://developer.baidu.com/wiki/index.php? Title = % E5 % B8 % AE % E5 % 8A % A9 % E6 % 96% E6 % A1 % A3 % E9 % A6 % 87% E9 % A1 % B5/web % E5 % BA % 94% E7 % 94% A8 % E6 % 8E % A5 % E5 % 85% A5/SDK

Instance code:
The code is as follows:
/**
* Author: hankcs
* Date: 14-3-29
* Time: PM
*/
Ini_set ("max_execution_time", 36000 );
Require_once '../bcs. class. php ';
Require_once '../krumo/class. krumo. php ';
$ Host = 'BCS .duapp.com ';
$ Ak = 'Your public key ';
$ Sk = 'Your private key ';
$ Bucket = 'name of the bucket to be downloaded ';
$ 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 );
// Download them
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 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.