百度开放云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,) )->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);
}
原文链接:https://www.f2er.com/php/24828.html/**
* 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,) )->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);
}