[擴充套件推薦]Aliyun-oss-laravel —— Laravel最好的OSS Storage擴充套件

悠悠山雨發表於2021-03-23

Aliyun-oss-laravel

專案地址

github.com/alphasnow/aliyun-oss-la...
packagist.org/packages/alphasnow/a...

安裝方法

  1. 如果您通過composer管理您的專案依賴,可以在你的專案根目錄執行:

     $ composer require alphasnow/aliyun-oss-laravel

    或者在你的composer.json中宣告依賴:

     "require": {
         "alphasnow/aliyun-oss-laravel": "~1.0"
     }
  2. 修改環境檔案.env

     ALIYUN_OSS_ACCESS_ID=
     ALIYUN_OSS_ACCESS_KEY=
     ALIYUN_OSS_BUCKET=
     ALIYUN_OSS_ENDPOINT=oss-cn-shanghai.aliyuncs.com
     ALIYUN_OSS_IS_CNAME=false
     ALIYUN_OSS_CDN_DOMAIN=
     ALIYUN_OSS_IS_CNAME=false
     ALIYUN_OSS_SSL=false
  3. (可選)修改配置檔案 config/filesystems.php

     'default' => env('FILESYSTEM_DRIVER', 'aliyun'),
     // ...
     'disks'=>[
         // ...
         'aliyun' => [
             'driver'     => 'aliyun',
             'access_id'  => env('ALIYUN_OSS_ACCESS_ID'),
             'access_key' => env('ALIYUN_OSS_ACCESS_KEY'),
             'bucket'     => env('ALIYUN_OSS_BUCKET'),
             'endpoint'   => env('ALIYUN_OSS_ENDPOINT', 'oss-cn-shanghai.aliyuncs.com'),
             'is_cname'   => env('ALIYUN_OSS_IS_CNAME', false),
             'cdn_domain' => env('ALIYUN_OSS_CDN_DOMAIN', ''),
             'ssl'        => env('ALIYUN_OSS_SSL', false),
             'debug'      => env('ALIYUN_OSS_DEBUG', false),
         ],
         // ...
     ]

快速使用

// 查詢資料夾
Storage::disk('aliyun')->files($directory);
Storage::disk('aliyun')->allFiles($directory);

// 寫入檔案
Storage::disk('aliyun')->put('path/to/file/file.jpg', $contents); 
Storage::disk('aliyun')->putFile('path/to/file/file.jpg', 'local/path/to/local_file.jpg');

// 讀取檔案
Storage::disk('aliyun')->get('path/to/file/file.jpg'); 
Storage::disk('aliyun')->exists('path/to/file/file.jpg'); 
Storage::disk('aliyun')->size('path/to/file/file.jpg'); 
Storage::disk('aliyun')->lastModified('path/to/file/file.jpg');

// 讀取資料夾
Storage::disk('aliyun')->directories($directory); 
Storage::disk('aliyun')->allDirectories($directory); 

// 檔案操作
Storage::disk('aliyun')->copy('old/file1.jpg', 'new/file1.jpg');
Storage::disk('aliyun')->move('old/file1.jpg', 'new/file1.jpg');
Storage::disk('aliyun')->rename('path/to/file1.jpg', 'path/to/file2.jpg');

Storage::disk('aliyun')->putRemoteFile('target/path/to/file/jacob.jpg', 'http://example.com/jacob.jpg');
Storage::disk('aliyun')->url('path/to/img.jpg');

Storage::disk('aliyun')->temporaryUrl('path/to/img.jpg',3600);

Storage::disk('aliyun')->prepend('file.log', 'Prepended Text'); 
Storage::disk('aliyun')->append('file.log', 'Appended Text');

Storage::disk('aliyun')->delete('file.jpg');
Storage::disk('aliyun')->delete(['file1.jpg', 'file2.jpg']);

// 資料夾操作
Storage::disk('aliyun')->makeDirectory($directory); 
Storage::disk('aliyun')->deleteDirectory($directory); 
本作品採用《CC 協議》,轉載必須註明作者和本文連結
轉載請告知

相關文章