PHP code example of laungkahung / laravel-cos-slice
1. Go to this page and download the library: Download laungkahung/laravel-cos-slice 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/ */
laungkahung / laravel-cos-slice example snippets
\LaravelUploader::routes();
// custom
\LaravelUploader::routes([
'as' => 'files.upload',
'middleware' => ['auth'],
//...
]);
return [
'disks' => [
//...
'cos' => [
'driver' => 'cos',
'app_id' => env('COS_APP_ID'),
'secret_id' => env('COS_SECRET_ID'),
'secret_key' => env('COS_SECRET_KEY'),
'region' => env('COS_REGION', 'ap-guangzhou'),
'bucket' => env('COS_BUCKET'), // 不带数字 app_id 后缀
'cdn' => env('COS_CDN'),
'signed_url' => false,
'prefix' => env('COS_PATH_PREFIX'), // 全局路径前缀
'guzzle' => [
'timeout' => env('COS_TIMEOUT', 60),
'connect_timeout' => env('COS_CONNECT_TIMEOUT', 60),
],
],
//...
]
];
$disk = Storage::disk('cos');
// create a file
$disk->put('avatars/filename.jpg', $fileContents);
// check if a file exists
$exists = $disk->has('file.jpg');
// get timestamp
$time = $disk->lastModified('file1.jpg');
$time = $disk->getTimestamp('file1.jpg');
// copy a file
$disk->copy('old/file1.jpg', 'new/file1.jpg');
// move a file
$disk->move('old/file1.jpg', 'new/file1.jpg');
// get file contents
$contents = $disk->read('folder/my_file.txt');
shell
$ php artisan vendor:publish --provider=Laungkahung\\LaravelCosSlice\\UploadServiceProvider