zgldh / qiniu-laravel-storage

Qiniu 云储存 Laravel 5 Storage版
MIT License
521 stars 79 forks source link

获取指定空间的文件列表 出错 #46

Closed isettle closed 6 years ago

isettle commented 7 years ago

环境


1、PHP 7.0.7 (cli) (built: Jun  2 2017 14:31:29) ( NTS )

2、"zgldh/qiniu-laravel-storage": "^0.8.0"

3、"laravel/framework": "5.4.*"

报错:


(1/1) ErrorExceptionUndefined offset: 2
--
in QiniuAdapter.php (line 436)
at HandleExceptions->handleError(8, 'Undefined offset: 2', '/vagrant/datang/vendor/zgldh/qiniu-laravel-storage/src/QiniuAdapter.php', 436, array('directory' => 'image', 'recursive' => true, 'bucketMgr' => object(BucketManager), 'items' => array('items' => array(array('key' => 'image/12123123.jpg', 'hash' => 'FqQz0ZXT9qeOErEDc54kEoVC3WI1', 'fsize' => 5560, 'mimeType' => 'image/jpeg', 'putTime' => 15030355030414385, 'type' => 0), array('key' => 'image/35aa0aa4eff6af6e20971e8b8bca9f91.jpeg', 'hash' => 'FqQz0ZXT9qeOErEDc54kEoVC3WI1', 'fsize' => 5560, 'mimeType' => 'image/jpeg', 'putTime' => 15030355295198346, 'type' => 0), array('key' => 'image/583.png', 'hash' => 'Fgk-ysKo3i8VkdNUORx76KIOkdrH', 'fsize' => 21516, 'mimeType' => 'image/png', 'putTime' => 15040840088926407, 'type' => 0), array('key' => 'image/700.png', 'hash' => 'FgejAbuK5m0P-How-m-bnsGO-oxa', 'fsize' => 13985, 'mimeType' => 'image/png', 'putTime' => 15040840595412069, 'type' => 0), array('key' => 'image/738.png', 'hash' => 'Fq99N7s0ZTQ5iY_Me1GK6dKLx8r8', 'fsize' => 21987, 'mimeType' => 'image/png', 'putTime' => 15040784690430097, 'type' => 0), array('key' => 'image/812.png', 'hash' => 'FgepfHIXWrmWRVNaDyRqGBamlifG', 'fsize' => 22693, 'mimeType' => 'image/png', 'putTime' => 15040643336408509, 'type' => 0), array('key' => 'image/a29e0ba43a7be2547b0fc11c3211ee49.jpeg', 'hash' => 'FqQz0ZXT9qeOErEDc54kEoVC3WI1', 'fsize' => 5560, 'mimeType' => 'image/jpeg', 'putTime' => 15034727831122215, 'type' => 0), array('key' => 'image/c475e719822650273c8c075574d73b92.jpeg', 'hash' => 'FqQz0ZXT9qeOErEDc54kEoVC3WI1', 'fsize' => 5560, 'mimeType' => 'image/jpeg', 'putTime' => 15040025801726937, 'type' => 0))), 'marker' => null))in QiniuAdapter.php (line 436)
at QiniuAdapter->listContents('image', true)in Filesystem.php (line 271)
at Filesystem->listContents('image', true)in FilesystemAdapter.php (line 422)
at FilesystemAdapter->files('image', true)in StaticController.php (line 23)
at StaticController->index()

……

定位在这儿,看了看PHP7的 list 函数,和PHP5的不一样。 我删除了 $marker,,把foreach ($items as $item) {改成了foreach ($items['item'] as $item) {

原方法:

    public function listContents($directory = '', $recursive = false)
    {
        $bucketMgr = $this->getBucketManager();

        list($items, $marker, $error) = $bucketMgr->listFiles($this->bucket, $directory);
        if ($error !== null) {
            $this->logQiniuError($error);

            return array();
        } else {
            $contents = array();
            foreach ($items as $item) {
                $normalized = [
                    'type'      => 'file',
                    'path'      => $item['key'],
                    'timestamp' => $item['putTime']
                ];

                if ($normalized['type'] === 'file') {
                    $normalized['size'] = $item['fsize'];
                }

                array_push($contents, $normalized);
            }

            return $contents;
        }
    }
zgldh commented 7 years ago

查了下,发现是 qiniu/php-sdk 7.2 改API返回数据结构了 https://github.com/qiniu/php-sdk/commit/60a002bae880597a8051cf140a381b7e01c39b7d 。。我修修看

zgldh commented 6 years ago

v0.8.3 已经修复