PHP code example of minz / laravel-qiniu-oss

1. Go to this page and download the library: Download minz/laravel-qiniu-oss library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

minz / laravel-qiniu-oss example snippets


'providers' => [
    ......
    \Minz\Laravel\Qiniu\OSS\QiniuOssServiceProvider::class,
],



return [
   'disks' => [
        //...
        "qiniu" => [
            'driver' => "qiniu",
            'access_key' => env('QINIU_ACCESS_KEY'),
            'access_secret' => env('QINIU_SECRET_KEY'),
            'bucket' => env('QINIU_BUCKET'),
            'domain' => env('QINIU_DOMAIN'),
            'ssl' => false,  //是否使用ssl协议
            'public' => false, //是否为公共读 默认为私有
            'root' => storage_path('app/public'),
        ]
    ]
];

$disk = Storage::disk('qiniu');

#是否存在key
$disk->has($key);

#获取key metadata
$disk->getMetadata($key);

#获取key size
$disk->getSize($key);

#获取mimeType
$disk->getMimetype($key);

#读取文件
$disk->read($key);

#extension
#获取视频类object时长
$disk->videoDuration($key)

#获取object baseUrl
$disk->getUrl($key);

#获取上传token
$disk->uploadToken("dir1/dir2/demo.mp3")

#下载指定文件
$disk->downloadFile($key, $localFileName, $expires)

#获取下载url,私有bucket会带有token, alias:别名
$disk->getDownloadUrl($key, $alias = null, $expires);

$disk = Storage::disk('qiniu');
/**
 * @param string|null $path 当前存储object的绝对路径,包含当前object name, eg: dir1/dir2/demo.mp3
 * @param int $expires  过期时间 s
 * @param array|null $policy 请参照七牛OSS文档
 * @param bool $strictPolicy
 * @return string
 */
$config = $disk->uploadToken($path, $expire, $policy, $strictPolicy);