|
<!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; |
|
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); |
|
|
|
|
|
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(); |
|
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> |
|
|