关于php:扩展推荐Aliyunosslaravel-Laravel最好的OSS-Storage扩展

57次阅读

共计 2326 个字符,预计需要花费 6 分钟才能阅读完成。

我的项目地址

https://github.com/alphasnow/aliyun-oss-laravel
https://packagist.org/packages/alphasnow/aliyun-oss-laravel

装置办法

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

正文完
 0