listFiles() public method

列取空间的文件列表
public listFiles ( $bucket, $prefix = null, $marker = null, $limit = 1000, $delimiter = null ) : array
$bucket 空间名
$prefix 列举前缀
$marker 列举标识符
$limit 单次列举个数限制
$delimiter 指定目录分隔符
return array 包含文件信息的数组,类似:[ { "hash" => "", "key" => "", "fsize" => "", "putTime" => "" }, ... ]
 public function getList()
 {
     $size = $this->request->get('size', $this->listSize);
     $start = $this->request->get('start', '');
     $auth = new Auth(config('ueditor.core.qiniu.accessKey'), config('ueditor.core.qiniu.secretKey'));
     $bucketManager = new BucketManager($auth);
     list($items, $marker, $error) = $bucketManager->listFiles(config('ueditor.core.qiniu.bucket'), $this->path, $start, $size);
     if ($error) {
         return ["state" => $error->message(), "list" => array(), "start" => $start, "total" => 0];
     }
     if (empty($items)) {
         return ["state" => "no match file", "list" => array(), "start" => $start, "total" => 0];
     }
     $files = [];
     foreach ($items as $v) {
         if (preg_match("/\\.(" . $this->allowFiles . ")\$/i", $v['key'])) {
             $files[] = array('url' => rtrim(config('ueditor.core.qiniu.url'), '/') . '/' . $v['key'], 'mtime' => $v['mimeType']);
         }
     }
     if (empty($files)) {
         return ["state" => "no match file", "list" => array(), "start" => $start, "total" => 0];
     }
     /* 返回数据 */
     $result = ["state" => "SUCCESS", "list" => $files, "start" => $start, "total" => count($files)];
     return $result;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function listContents($directory = '', $recursive = false)
 {
     $list = [];
     $r = $this->bucketManager->listFiles($this->bucket, $directory);
     foreach ($r[0] as $v) {
         $list[] = $this->normalizeFileInfo($v);
     }
     return $list;
 }
Example #3
0
 static function list_file($bucketName, $path = null)
 {
     if ($path && substr($path, 0, 1) == "/") {
         $path = substr($path, 1);
     }
     //echo $path;exit;
     //$path = null;
     $auth = self::get_auth();
     $bucketManager = new BucketManager($auth);
     list($items, $marker, $error) = $bucketManager->listFiles($bucketName, $path, null, 2);
     return $items;
 }
Example #4
0
<?php

require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);
$bucketMgr = new BucketManager($auth);
$bucket = 'Bucket_Name';
$prefix = '';
$marker = '';
$limit = 3;
list($iterms, $marker, $err) = $bucketMgr->listFiles($bucket, $prefix, $marker, $limit);
if ($err !== null) {
    echo "\n====> list file err: \n";
    var_dump($err);
} else {
    echo "Marker: {$marker}\n";
    echo "\nList Iterms====>\n";
    var_dump($iterms);
}
Example #5
0
 /**
  * 获取七牛文件列表
  * @return array
  */
 public function listFile()
 {
     $client = new BucketManager($this->auth);
     return $client->listFiles($this->bucket);
 }
Example #6
0
    }
}
$ak = $_SESSION['ak'];
$sk = $_SESSION['sk'];
$bucket = $_SESSION['bucket'];
$domain = $_SESSION['domain'];
$mode = $_SESSION['mode'];
$width = $_SESSION['width'];
$height = $_SESSION['height'];
$sn = $_SESSION['sn'];
console_log("Access Info: {$ak}, {$sk}, {$bucket}");
console_log("Op Info: {$mode}, {$width}, {$height}");
console_log("Selected File: {$sn}");
$auth = new Auth($ak, $sk);
$bm = new BucketManager($auth);
list($items, $marker, $err) = $bm->listFiles($bucket);
// 尝试列举空间中的文件
if ($err != null) {
    //echo "列举文件失败:(".$err->code().") ".$err->message();
} else {
    // 过滤出若干张jpg图片用于展示。
    foreach ($items as $item) {
        if ($item['mimeType'] == 'image/jpeg') {
            $pics[] = $item;
            if (count($pics) >= 10) {
                break;
            }
        }
    }
}
//var_dump($pics);
Example #7
0
 public function listFiles()
 {
     $res = array("code" => 0, "msg" => '');
     $bucketMgr = new BucketManager(self::auth());
     $bucket = 'blog';
     $prefix = '';
     $marker = '';
     $limit = '';
     list($items, $marker, $err) = $bucketMgr->listFiles($bucket, $prefix, $marker, $limit);
     if ($err !== null) {
         $res["code"] = 1;
         $res["msg"] = $err;
     } else {
         $time = time() + 7 * 24 * 60 * 60;
         foreach ($items as $item) {
             $url = self::QI_NIU_DOMAIN . $item["key"] . "?e={$time}";
             $sign = hash_hmac('sha1', $url, self::getKey("secret"), true);
             $token = self::getKey("access") . ":" . self::urlsafe_base64_encode($sign);
             $item["url"] = $url . "&token={$token}";
             $item["url"] = self::QI_NIU_DOMAIN_BLOG . $item["key"];
             $newItems[] = $item;
         }
         $res["data"] = $newItems;
     }
     echo json_encode($res);
 }