upic / index.html
nagose's picture
Update index.html
c7d55ef verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload</title>
<style>
body {
background-image: url('https://openai-75050.gzc.vod.tencent-cloud.com/openaiassets_b2edbcb71bed2e127d071803cc655cbf_2579861726125066950.jpg');
background-size: contain; /* 改为 contain 以适应屏幕 */
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center; /* 居中显示 */
}
</style>
</head>
<body>
<input type="file" id="fileInput">
<button onclick="uploadFile()">Upload</button>
<script>
async function uploadFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (!file) {
alert('Please select a file first.');
return;
}
const formData = new FormData();
formData.append('file', file);
// 输出 FormData 内容
for (let [key, value] of formData.entries()) {
console.log(`${key}:`, value);
}
try {
const response = await fetch('https://webpho.pages.dev/uploadtx', {
method: 'POST',
body: formData
});
const result = await response.json(); // 假设服务器返回 JSON 格式的数据
if (response.ok) {
alert('File uploaded successfully! Server response: ' + JSON.stringify(result));
} else {
alert('File upload failed. Server response: ' + JSON.stringify(result));
}
} catch (error) {
console.error('Error uploading file:', error);
alert('Error uploading file.');
}
}
</script>
</body>
</html>