<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‘); ???}
上传多张图片 ??multiple使用
原文地址:https://www.cnblogs.com/G921123/p/10218030.html