接口地址https://lwcat.cn/hlximage.php
上传file
返回json,url为图片链接
演示示例:https://lwcat.cn/list/%E8%91%AB%E8%8A%A6%E4%BE%A0%E5%9B%BE%E7%89%87%E4%B8%8A%E4%BC%A0%E6%BC%94%E7%A4%BA/index.html
可以右键查看源代码
对接示例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>图片上传示例</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css" media="all">
<style>
.layui-upload {
text-align: center;
margin-top: 50px;
}
#previewImage {
max-width: 100%;
height: auto;
}
</style>
<script src="https://cdn.lwcat.cn/jquery/jquery.js"></script>
<script src="https://cdn.lwcat.cn/layui/layui.js"></script>
</head>
<body>
<div class="layui-upload">
<button type="button" class="layui-btn" id="uploadImage">上传图片</button>
<div class="layui-upload-list">
<p id="uploadStatus"></p>
</div>
</div>
<script>
layui.use('upload', function(){
var upload = layui.upload;
var layer = layui.layer;
var uploadInst = upload.render({
elem: '#uploadImage'
,url: 'https://lwcat.cn/hlximage.php'
,field: 'file'
,accept: 'images'
,exts: 'jpg|jpeg|png'
,before: function(obj){
layer.load();
}
,done: function(res){
layer.closeAll('loading');
if(res.url){
layer.msg('上传成功!', {icon: 1});
$('#uploadStatus').html('上传成功,图片链接:<a href="'+ res.url +'" target="_blank">'+ res.url +'</a>');
} else {
layer.msg('上传失败:'+ res.error, {icon: 2});
$('#uploadStatus').html('上传失败:'+ res.error);
}
}
,error: function(){
layer.closeAll('loading');
layer.msg('上传失败,请重试!', {icon: 2});
$('#uploadStatus').html('上传失败,请重试!');
}
});
});
</script>
</body>
</html>
评论 (0)