多个模块发布
基本方法
$up = new \upload\Upload;
$up->upload();
部署说明
将upload.zip 文件直接解压到 /extend 文件夹下
参数设置
//实例化传参
$up = new \upload\Upload([
    'maxSize' => 2048,    //文件大小限制
    'exts' => ['jpg', 'gif', 'png', 'jpeg'],    //文件名后缀限制,数组形式
    'savePath' => '/public/upload',    //文件保存物理目录路径,相对于项目根目录,前面有斜杠,后面没有
    'urlPath' => '/upload',    //文件URL目录路径,相对于站点根目录,前面有斜杠,后面没有
    'autoSub' => true,    //是否按日期使用子目录,如果是,在savePath下还会有“年/月/日”目录,否则直接保存在savePath
    'autoName' => true,    //是否自动命名文件,如果是将以“年 月 日 时 分 秒 随机数”的方式命名文件,否则保留原文件名
    'replace' => true    //是否覆盖已存在的文件
]);
$up->upload();
 
//动态传参
$up = new \upload\Upload;
$up->maxSize = 2048;
$up->exts = ['jpg', 'gif', 'png', 'jpeg'];
$up->savePath = '/public/upload';
$up->urlPath = '/upload';
$up->autoSub = true;
$up->autoName = true;
$up->replace = true;
$up->upload();
 
//所有参数都是可选,不设置就为默认值
上传表单
单文件上传
<form action="" enctype="multipart/form-data" method="post">
    <input type="file" name="file">
    <button type="submit">上传</button>
</form>
 
多文件上传
<form action="" enctype="multipart/form-data" method="post">
    <input type="file" name="file0">
    <input type="file" name="file1">
    <input type="file" name="file2">
    <input type="file" name="file3">
    <button type="submit">上传</button>
</form>
 
以数组形式多文件上传
<form action="" enctype="multipart/form-data" method="post">
    <input type="file" name="file[]">
    <input type="file" name="file[]">
    <input type="file" name="file[]">
    <input type="file" name="file[]">
    <button type="submit">上传</button>
</form>
结果返回
$up = new \upload\Upload;
var_dump($up->upload());
 
//因为是支持多文件上传,所以上传结果会是一个数组,把每个文件的结果都返回:
上传成功返回:
[
    [
        'result' => true,    //上传成功
        'url' => '/upload/2019/12/06/20191206161246845.jpg'    //上传文件的URL,相对于站点根目录
    ],
]
上传失败返回:
[
    [
        'result' => false,    //上传失败
        'error' => '上传文件大小超过限制'    //失败原因
    ]
    // more
]
				
				下载类库 (大小:1k)(更新时间:2023-11-30 09:53:42)