upload_directory() публичный Метод

将目录中的所有文件进行上传,每个文件为单独object,object命名方式下详: 如有 /home/worker/a/b/c.txt 需上传目录为$dir=/home/worker/a object命令方式为 1. object默认命名方式为 “子目录名 +文件名”,如上述文件c.txt,默认为 '/b/c.txt' 2. 增强命名模式,在$opt中有可选参数进行配置 举例说明 :prefix . has_sub_directory?"/b":"" . '/c.txt'
public upload_directory ( string $bucket, string $dir, $opt = [] ) : array
$bucket string (Required)
$dir string (Required)
Результат array 数组形式的上传结果 'success' => int 上传成功的文件数目 'skipped' => int 被跳过的文件 'failed' => array() 上传失败的文件
Пример #1
0
    trigger_error("Can not get thread num");
    exit;
}
$thread_num = $argv[1];
$thread_id = $argv[2];
trigger_error("Upload dir thread start, thread_num=[{$thread_num}], thread_id=[{$thread_id}]");
//开始上传
$baidu_bcs = new BaiduBCS($ak, $sk, $host);
$opt = array(BaiduBCS::IMPORT_BCS_PRE_FILTER => 'pre_filter', BaiduBCS::IMPORT_BCS_POST_FILTER => 'post_filter', "prefix" => $prefix, "has_sub_directory" => $has_sub_directory);
if (isset($seek_object_id)) {
    $opt["seek_object_id"] = $seek_object_id;
}
if (isset($seek_object)) {
    $opt["seek_object"] = $seek_object;
}
$baidu_bcs->upload_directory($bucket, $upload_dir, $opt);
/*
 * 可定制化,发送前操作
 * 比如返回 boolean型
 */
function pre_filter($bucket, $object, $file, &$opt)
{
    //文件名的md5 % thread_num 得到的余数若等于thread_id,上传该文件
    global $thread_num, $thread_id;
    $crc32 = crc32($object);
    $mod = ($crc32 > 0 ? $crc32 : -$crc32) % $thread_num;
    if ($mod == $thread_id) {
        return true;
    } else {
        return false;
    }