mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-02 17:59:53 +08:00
58 lines
1.7 KiB
Plaintext
58 lines
1.7 KiB
Plaintext
<% var title="图片上传"%>
|
||
<%- include('utils/header', {title}); %>
|
||
<body>
|
||
<div class="container">
|
||
<form id="formId" action="/img/upload" method="post" enctype="multipart/form-data">
|
||
<h2>单图上传</h2>
|
||
<input type="file" name="file" accept=".jpg, .jpeg, .png, .hdr, .exr">
|
||
<input id="submit" type="button" value="提交">
|
||
</form>
|
||
<a id="search" class="btn btn-default">查询</a>
|
||
<p>
|
||
<h2>查询结果</h2>
|
||
<br>
|
||
原始名称:<span id="name"></span>
|
||
<br>
|
||
上传时间:<span id="lastModified"></span>
|
||
<br>
|
||
文件大小:<span id="size"></span>
|
||
<br>
|
||
图片地址:<a id="url" href=""></a>
|
||
</p>
|
||
</div>
|
||
</body>
|
||
<script>
|
||
$('#search').click(function () {
|
||
$.ajax({
|
||
url: '/img/search',
|
||
type: 'get',
|
||
success: function (data) {
|
||
const {name, lastModified, size, url} = data[0];
|
||
$('#name').text(name);
|
||
$('#lastModified').text(lastModified);
|
||
$('#size').text(size);
|
||
$('#url').text(url).attr('href', url);
|
||
}
|
||
});
|
||
});
|
||
$("#submit").click(function () {
|
||
$.ajax({
|
||
url: '/img/upload',
|
||
type: 'post',
|
||
data: new FormData($('#formId')[0]),
|
||
processData: false,
|
||
contentType: false,
|
||
success: function (data) {
|
||
if (data.res.status === 200) {
|
||
alert("上传成功");
|
||
} else {
|
||
alert("上传失败");
|
||
}
|
||
console.log(data);
|
||
}
|
||
});
|
||
return false; // 必须返回false,否则表单会自己再做一次提交操作,并且页面跳转
|
||
});
|
||
</script>
|
||
</html>
|