This article uses Baidu open cloud PHPSDK to download Baidu cloud disk files in batches. For more information, see. 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 );
}