TP5多文件上传,可用于调查:
附前台HTML
<div id="image{$k}" class="btn-control">
图片上传:
<input type="file" id="bgyxun[{$k}]" class="image_bgy" placeholder="图片" value=""
<input type="hidden" name="img[{$k}][]" class="form-control" placeholder="">
</div>
<span class="add-more glyphicon glyphicon-plus"></span>
TP5后台文件上传
public function ajaximg(){
$base64_img = trim(input('b64'));
$up_dir = './uploads/form/';//存放在当前目录的upload文件夹下
if(preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_img, $result)){
$type = $result[2];
if(in_array($type,array('pjpeg','jpeg','jpg','gif','bmp','png'))){
$new_file = $up_dir.date('YmdHis_').'.'.$type;
if(file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_img)))){
$img_path = str_replace('../../..', '', $new_file);
$img_path = str_replace('./uploads/', '', $img_path);
return json(['re'=>$img_path]);
}else{
return json(['re'=>'失败']);
}
}else{
//文件类型错误
return json(['re'=>'错误']);
}
}else{
//文件错误
return json(['re'=>'错误1']);
}
}