Aliyun-oss-storage for Laravel

The extension has learned from some excellent codes, integrated various parties, and made more optimization at the same time. More perfect interfaces and plug-ins will be added to create the best OSS Storage extension for Laravel

Address of the project: alphasnow. Making. IO/aliyun – oss – laravel

Runtime environment

  • PHP 7.0 +
  • cURL extension
  • Laravel 5.5 +

Installation method

  1. If you manage your project dependencies in Composer, it can be run in your project root directory:

     $ composer require alphasnow/aliyun-oss-laravel
    

    Or declare a dependency in your composer.json:

    "Require ": {"alphasnow/aliyun-oss-laravel": "~2.0"}
  2. Modify the environment file.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_SSL=false
  3. (Optional) Modify the configuration file 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', ''),
            'is_ssl'     => env('ALIYUN_OSS_IS_SSL', false),
        ],
        // ...
    ]

Quick to use

use IlluminateSupportFacadesStorage;
$storage = Storage::disk('aliyun');

File is written to

Storage::disk('aliyun')->putFile('prefix/path', '/local/path/file.txt');
Storage::disk('aliyun')->putFileAs('prefix/path', '/local/path/file.txt', 'file.txt');

Storage::disk('aliyun')->put('prefix/path/file.txt', file_get_contents('/local/path/file.txt'));
$fp = fopen('/local/path/file.txt','r');
Storage::disk('aliyun')->put('prefix/path/file.txt', $fp);
fclose($fp);

Storage::disk('aliyun')->putRemoteFile('prefix/path/file.txt', 'http://example.com/file.txt');

Storage::disk('aliyun')->prepend('prefix/path/file.txt', 'Prepend Text'); 
Storage::disk('aliyun')->append('prefix/path/file.txt', 'Append Text');

File query

Storage::disk('aliyun')->url('prefix/path/file.txt');
Storage::disk('aliyun')->temporaryUrl('prefix/path/file.txt', CarbonCarbon::now()->addMinutes(30));

Storage::disk('aliyun')->get('prefix/path/file.txt'); 

Storage::disk('aliyun')->exists('prefix/path/file.txt'); 
Storage::disk('aliyun')->size('prefix/path/file.txt'); 
Storage::disk('aliyun')->lastModified('prefix/path/file.txt');

File operations

Storage::disk('aliyun')->copy('prefix/path/file.txt', 'prefix/path/file_new.txt');
Storage::disk('aliyun')->move('prefix/path/file.txt', 'prefix/path/file_new.txt');
Storage::disk('aliyun')->rename('prefix/path/file.txt', 'prefix/path/file_new.txt');

File deletion

Storage::disk('aliyun')->delete('prefix/path/file.txt');
Storage::disk('aliyun')->delete(['prefix/path/file1.txt', 'prefix/path/file2.txt']);

Folder operation

Storage::disk('aliyun')->makeDirectory('prefix/path'); Storage::disk('aliyun')->deleteDirectory('prefix/path'); // select Storage::disk('aliyun')->files('prefix/path') from Storage::disk('aliyun')->files('prefix/path'); // file Storage::disk('aliyun')->allFiles('prefix/path'); // query for directories that are directories directories ::disk('aliyun')->directories('prefix/path'); Storage::disk('aliyun')->allDirectories('prefix/path');

Project Git repository


Aliyun OSS document