代码示例

文件校验
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 类型
imagejpg, jpeg, png, gif, webpimage/jpeg, image/png, image/gif, image/webp
videomp4, webmvideo/mp4, video/webm
audiomp3, wavaudio/mpeg, audio/wav
filepdf, doc, docx, xls, xlsx, zipapplication/pdf, ...