代码示例
文件校验
use app\common\service\FileService;
// 校验文件
$result = FileService::check($file, 'image', 10485760);
// $result = ['ok' => true, 'msg' => ''] or ['ok' => false, 'msg' => '错误信息']
安全上传
// 使用助手函数
$result = safeMoveUpload($file, 'uploads/editor', 'image', 10485760);
// $result = ['ok' => true, 'url' => '/uploads/editor/xxx.jpg'] or ['ok' => false, 'msg' => '错误信息']
支持的文件类型
// image: jpg, jpeg, png, gif, webp
// video: mp4, webm
// audio: mp3, wav
// file: pdf, doc, docx, xls, xlsx, zip
支持的文件类型
| 类型 | 扩展名 | MIME 类型 |
|---|---|---|
| image | jpg, jpeg, png, gif, webp | image/jpeg, image/png, image/gif, image/webp |
| video | mp4, webm | video/mp4, video/webm |
| audio | mp3, wav | audio/mpeg, audio/wav |
| file | pdf, doc, docx, xls, xlsx, zip | application/pdf, ... |