PHP code example of isszz / think-filesystem-driver
1. Go to this page and download the library: Download isszz/think-filesystem-driver 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' );
isszz / think-filesystem-driver example snippets
return [
'disks' => [
'qiniu' => [
'type' => 'qiniu' ,
'access_key' => env('qiniu.access_key' , 'xxxxxxxxxxxxxxxx' ),
'secret_key' => env('qiniu.secret_key' , 'xxxxxxxxxxxxxxxx' ),
'bucket' => env('qiniu.bucket' , 'test' ),
'domain' => env('qiniu.domain' , 'xxx.xxx.top' ),
],
'oss' => [
'type' => 'oss' ,
'access_key' => env('oss.access_key' , 'xxxxxxxxxxxxxxxx' ),
'secret_key' => env('oss.secret_key' , 'xxxxxxxxxxxxxxxx' ),
'bucket' => env('oss.bucket' , 'test' ),
'domain' => env('oss.domain' , 'xxx.xxx.top' ),
'is_cname' => env('oss.is_cname' , false ),
'root' => env('oss.root' , '' ),
],
'cos' => [
'type' => 'cos' ,
'region' => env('cos.region' , 'ap-shanghai' ),
'credentials' => [
'appId' => env('cos.app_id' ),
'secretId' => env('cos.secret_id' ),
'secretKey' => env('cos.secret_key' ),
],
'bucket' => env('cos.bucket' ),
'cdn' => env('cos.cdn' ),
'scheme' => env('cos.scheme' , 'https' ),
'read_from_cdn' => env('cos.read_from_cdn' , false ),
'timeout' => env('cos.timeout' , 60 ),
'connect_timeout' => env('cos.connect_timeout' , 60 ),
],
]
];
use think \facade \Filesystem ;
$disk = Filesystem::disk('qiniu' );
$disk->addPlugin();
$file = request()->file('file' );
$filepath = $disk->putFile('mypath' , $file);
$url = $disk->getUrl($filepath);
dd([$filepath, $url]);