Files
danmaku/views/imgupload.ejs
2023-02-18 23:34:04 +08:00

58 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<% 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>