Tôi đang làm việc thông qua tập lệnh tải lên tệp nhỏ (trải nghiệm học tập) và tôi nhận thấy rằng khi chọn tệp liên quan đến văn phòng microsoft (ví dụ: .doc
hoặc .docx
) một loại quy định:Xác định loại nội dung không xác định bằng tệp Html5 api
Đối với các file .doc tôi mong đợi đã loại được "application/msword"
và dọc theo tàu cùng .docx nghĩ là "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
.
Trong trường hợp loại không thể xác định được là hành động chính xác để xem xét phần mở rộng của tệp và khớp với loại nội dung "mong đợi" đó?
Mẫu kịch bản:
<div id="fileUpload">
<input type="file" id="fileElem" style="display:none;" onchange="handleFiles(this.files)"/>
<a href="#" id="fileSelect">Select some files</a>
</div>
<script type="text/javascript">
var fileSelect = document.getElementById("fileSelect"),
fileElem = document.getElementById("fileElem");
fileSelect.addEventListener("click", function (e) {
if (fileElem) {
fileElem.click();
}
e.preventDefault();
}, false);
function handleFiles(files) {
console.log(files);
}
</script>
đây là danh sách loại mime hữu ích và được giữ nguyên. https://github.com/stretchr/filetypes.js – netalex
[Danh sách loại MIME] (http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) từ svn.apache.org. Xem [Nhận xét tài liệu PHP] (http://php.net/manual/en/function.mime-content-type.php#107798) – Bright