PHP code example of cdyun / thinkphp-upload
1. Go to this page and download the library: Download cdyun/thinkphp-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/ */
cdyun / thinkphp-upload example snippets
use Cdyun\ThinkphpUpload\UploadEnforcer;
$upload = new UploadEnforcer();
// 默认上传
$result = $upload->move(File文件);
// 指定上传路径
$result = $upload->path('uploads')->move(File文件);
// 指定文件名
$result = $upload->name('file.txt')->move(File文件);
// 自定义验证
$result = $upload->validate(['fileSize' => 1024])->move(File文件);
// 多个配置
$result = $upload->path('uploads')->validate(['fileSize' => 1024])->name('file.txt')->move(File文件);
return [
// 默认磁盘
'default' => 'oss',
// 磁盘列表
'disks' => [
// 本地上传
'local' => [
// 磁盘类型
'type' => 'local',
// 磁盘路径
'root' => app()->getRootPath() . 'public/bucket',
// 磁盘路径对应的外部URL路径
'url' => '/bucket',
// 可见性
'visibility' => 'public',
],
// 阿里云存储
'oss' => [
// 磁盘类型,不要修改直接使用Local驱动
'type' => 'local',
// 磁盘路径,改为存储桶
'root' => 'tzhapp2',
// 磁盘路径对应的外部URL路径,改为存储桶的域名,结尾不要带斜杠
'url' => '',
// 可见性
'visibility' => 'public',
],
// 更多的磁盘配置信息
],
];
return [
// 上传配置
'upload' => [
//上传文件大小100*1024KB
'fileSize' => 204800,
//上传图片大小
'imgSize' => 1024,
//上传文件后缀类型
'fileExt' => 'gif,jpg,jpeg,png,mp4,doc,docx,txt,pdf,xls,xlsx,ppt,pptx,mp3,wma,wav,zip',
//上传图片类型
'imgExt' => 'gif,jpg,jpeg,png',
//上传路径,默认为files
'path' => 'files',
//驱动模式配置信息
'stores' => [
//本地上传配置
'local' => [],
//七牛云上传配置
'qiniu' => [],
//oss上传配置
'oss' => [
'aki' => '',
'aks' => '',
'endpoint' => '',
'region' => "",
],
//cos上传配置
'cos' => [],
]
]
];