ThinkPHP5 通过ajax插入图片并实时显示(完整代码)
单张图片上传
展示图:
完整代码:
ajax上传图片练习 身份证正面
tp控制器代码
publicfunctionmeasurement() { $response=array(); //这是身份证正面 if(isset($_FILES['drawing'])&&$_FILES['drawing']['error']==0){ $drawing=request()->file('drawing'); $picture=$drawing->validate(['ext'=>'jpg,png,gif'])->move(ROOT_PATH.'static'.DS.'upload/mi/img'); } if(isset($picture)){ $filePaths='/static'.DS.'upload/mi/img/'.$picture->getSaveName(); $response['whether']=true; $response['site']=$filePaths; echojson_encode($response); } //正面结束 }
多个上传
展示:
完整代码:
文件上传 #front{ width:120px; height:120px; background-color:#8A6DE9; } #frontage{ width:120px; height:120px; background-color:#8A6DE9; } #banking{ width:120px; height:120px; background-color:#8A6DE9; } #house{ width:120px; height:120px; background-color:#8A6DE9; } 身份证正面:
身份证反面: