[Extension recommendation] alicloud object storage extension — laravel’s best aliyun OSS storage extension

Time:2021-4-20

Aliyun-oss-storage for Laravel

The extension draws on some excellent codes, integrates all parties, and makes more optimization. More perfect interfaces and plug-ins will be added to create the best OSS storage extension of laravel

Project address: alphasnow.github.io/aliyun -oss-laravel

Operating environment

  • PHP 7.0+
  • cURL extension
  • Laravel 5.5+

Installation method

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

     $ composer require alphasnow/aliyun-oss-laravel
    

    Or in your lifecomposer.jsonDeclare dependency in:

     "require": {
         "alphasnow/aliyun-oss-laravel": "~2.0"
     }
    
  2. Modify 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 configuration fileconfig/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 use

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

File write

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 operation

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');

//Query the first level subdirectory file
Storage::disk('aliyun')->files('prefix/path');
//Recursive query of multi level subdirectory files
Storage::disk('aliyun')->allFiles('prefix/path');

//  Query the first level subdirectory
Storage::disk('aliyun')->directories('prefix/path'); 
//Recursive query of multi level subdirectories
Storage::disk('aliyun')->allDirectories('prefix/path');

Project git warehouse
Alibaba cloud OSS document

Recommended Today

Analysis of super comprehensive MySQL statement locking (Part 1)

A series of articles: Analysis of super comprehensive MySQL statement locking (Part 1) Analysis of super comprehensive MySQL statement locking (Part 2) Analysis of super comprehensive MySQL statement locking (Part 2) Preparation in advance Build a system to store heroes of the Three KingdomsheroTable: CREATE TABLE hero ( number INT, name VARCHAR(100), country varchar(100), PRIMARY […]