Home >Backend Development >PHP Tutorial >PHP implements batch download of Baidu cloud disk files example sharing_PHP tutorial

PHP implements batch download of Baidu cloud disk files example sharing_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:17969browse

Baidu Open Cloud PhpSDK download address: 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

Example code:

Copy code The code is as follows:

/**
* Author: hankcs
* Date : 14-3-29
* Time : 10:29 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 = 'Bucket name to download' ;
$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); 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);
}

http://www.bkjia.com/PHPjc/751936.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/751936.htmlTechArticleBaidu Open Cloud PhpSDK download address: 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/S...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn