6232021-12-05 03:07:58
收藏
<div class="photoUpLoad">
<input id="photo" type="file" name="photo" accept="image/*">
</div>
<script src="/e/extend/upimg/layui/jquery.js"></script>
<script src="/e/extend/upimg/layui/layui.js"></script>
<script>
//一般直接写在一个js文件中
layui.use(['layer', 'form','upload'], function(e){
var layer = layui.layer,
form = layui.form,
upload = layui.upload;
//执行实例
var uploadInsta = upload.render({
elem: '#photo', //绑定元素
url: '/e/extend/upimg/upload.php', //上传接口
field:'file',
done: function(res){
//上传完毕回调
layer.msg(res.msg);
if(res.code){
$(".photo").html("<img src=/e/extend/upimg"+res.filepath+" style='width:150px'>");
$("[name='photo']").val(res.filepath);
}
},
error: function(res){
//请求异常回调
console.log(res)
}
});
});
</script>
帝国cms前台图片上传插件已人工检测,确认安全无毒,请放心下载。