上传多张图片 multiple使用
程序员文章站
2022-04-13 14:37:00
当前页面选择浏览: 选择文件: 选中的上传图片信息: 后台处理: ......
<form action="upload.php" method="post" enctype="multipart/form-data"> select images: <input type="file" name="img[]" multiple="multiple" /> <input type="submit" /> </form>
当前页面选择浏览:
选择文件:
选中的上传图片信息:
后台处理:
public function sub1() { $model = d('bidnotice'); $file = $_files['img']; $count = count($file['name']); for ($i = 0; $i < $count; $i++) { if ($file['size'][$i] > 3145728) { $this->error("上传文件超过限定大小");exit; } $name = strrchr($file['name'][$i], '.'); $str = rand(111, 999); $tmpname = date('y-m-d') . $str; $newname = $tmpname . $name; $upload_path = "../public/images/zhongbiao/"; $typearr = array('.jpg', '.jpeg', '.png'); if ($file['error'][$i] == 0) { if (in_array($name, $typearr)) { if (is_uploaded_file($file['tmp_name'][$i])) { if (move_uploaded_file($file['tmp_name'][$i], $upload_path . $newname)) { $fujian = "fujian".$i; // 拼接 每张图片存入对应的字段.数据库 设计 字段 dujian0,dujian1,dujian2... $data[$fujian] = $newname; } } } } } $data['lsnumber'] = $_post['lsnumber']; $data['city'] = $_post['city']; ... $model->add($data); $this->success("添加成功", 'goods/list'); }