Laravel admin 使用技巧 - 上传文件到阿里云

哦豁,见面了。

1.首先根据Laravel-admin 上提供的上传文档走哈。(第一步下载composer包)

composer require jacobcyl/ali-oss-storage:^2.1

 

2.去除限制不然报错很烦哦!

\vendor\jacobcyl\ali-oss-storage\src 文件下的AliOssAdapter.php的第570行全部注释!!!(切记 切记 切记)

就是他:if (!$this->has($path)) throw new FileNotFoundException($filePath.' not found');

3.(哈哈哈这下就走正规流程了)在config/app.php 中providers数组增加代码

Jacobcyl\AliOSS\AliOssServiceProvider::class,

 

4.在config/filesystem.php 中disks数组中增加代码, 其中access_id, access_key参数都是到阿里云提供

'oss' => [
        'driver'     => 'oss',
        'access_id'  => env('ALIYUN_ACCESS_KEY_ID'),
        'access_key' => env('ALIYUN_ACCESS_KEY_SECRET'),
        'bucket'     => env('ALIYUN_OSS_BUCKET'),
        'endpoint'   => env('ALIYUN_OSS_ENDPOINT'),
        'cdnDomain'  => env('ALIYUN_OSS_URL'),(这里别加http://或者https://)
        'ssl'        => false,
        'isCName'    => true,
        'debug'      => true,
    ],

'default' => env('FILESYSTEM_DRIVER', 'oss'),

 

5.在config/admin.php中修改upload配置

'upload' => [

// Disk in `config/filesystem.php`.
'disk' => 'oss', // 这里就是指向 disks 下面的 oss 配置

// Image and file upload path under the disk above.
'directory' => [
    'image' => 'images',
    'file'  => 'files',
],
],

 

6.就可以了:(下面就是正常用)

$form->image('img_src', __('广告图片'));
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐