Thinkphp多图上传只能传一张

    xiaoxiao2021-03-25  58

    在用thinkphp做多图上传的时候,按照官方文档的写法修改表单,

    如果需要使用多个文件上传,只需要修改表单,把

    <input type='file' name='photo'>

    改为

    <input type='file' name='photo1'><input type='file' name='photo2'><input type='file' name='photo3'>

    或者

    <input type='file' name='photo[]'><input type='file' name='photo[]'><input type='file' name='photo[]'>

    两种方式的多附件上传系统的文件上传类都可以自动识别。

    然后方法:

    $upload = new \Think\Upload();// 实例化上传类

    $upload->maxSize   =     3145728;// 设置附件上传大小

    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型

    $upload->rootPath  =     './Public/img/good/'; // 设置附件上传根目录

    $upload->savePath  =     ''; // 设置附件上传(子)目录

    $upload->autoSub   =     false;   //不自动新建子目录

    $upload->replace = true;//若同名则覆盖

    $upload->saveName = date("Y-m-d").'_'.mt_rand();

    却发现怎么上传都只能上传一张,

    研究了半天,

    原来是要把saveName写成

    $upload->saveName = array('uniqid','');   //表示唯一

    但是这样子好像就没有办法自定义名称了,

    还有表单按官方第一种数字的写法是无效的,必须第二种photo[ ]这样写才有效,不知道为什么,

    不知道哪位大神懂的,请赐教。

    转载请注明原文地址: https://ju.6miu.com/read-37434.html

    最新回复(0)