PHP code example of githen / laravel-upload
1. Go to this page and download the library: Download githen/laravel-upload library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
githen / laravel-upload example snippets
'localFile' => [
'driver' => 'local',
'root' => public_path(),
'url' => config('app.url'), // 生成url前缀
'permissions' => [
'file' => [
'public' => 0770,
'private' => 0600,
],
'dir' => [
'public' => 0770,
'private' => 0700,
],
],
],
return [
/**
|--------------------------------------------------------------------------
| 文件上传配置
|--------------------------------------------------------------------------
| '标识' => [
* 'size' => 3, //文件大小上限 类型int 单位MB
* 'ext' => ['png', 'jpg'] // 支持的文件类型,类型array
* 'resize' => [200, 200] // 若为图片类型,自动处理图片为200X200
* 'path' => 'uploads/'. date('Y/m/d'), // 文件实际存储目录
* ]
*/
'global' => [
'tmp' => 'uploads/tmp', // 临时目录,在表单提交时再将文件移动到path目录
'path' => 'uploads', // 实际存储目录
'name' => 'file', // 文件上传时文件对应的key
'auth' => ['auth'], // 上传controller加载的中间件
'filesystem' => 'localFile', // 使用的文件系统
'thumb' => 'thumb', // 图片类型缩略图名称,a.png => a_thumb.png
],
'img' => [
'size' => 3, // MB
'ext' => ['.png', '.jpg', '.jpeg', '.zip'],
'resize' => [200,200], // 原图等比压缩,只有图片格式有效,不配置使用原图
'thumb_resize' => [200,200], // 生成缩略图,只有图片格式有效,不配置则不生成
'path' => 'uploads/'. date('Y/m/d'),
]
];
//app('jiaoyu.move') 以单例形貌注入,执行迁移操作
// $from 文件地址
// $to 需要迁移到的目录
// 如果存在缩略图,一并迁移
$result = app('jiaoyu.upload')->move($from, $to);
// 返回数据结构
[
"code" => 0, // 0 成功 1失败
"message" => "成功", // 执行说明
"path" => '', // 新文件的目录,缩略图默认在文件名后加入缩略图标识,`upload.global.thumb`
]
// $file 要删除的文件
$result = app('jiaoyu.upload')->remove($file);
// 返回数据结构
[
"code" => 0, // 0 成功 1失败
"message" => "成功删除", // 执行说明
]