如果你在談論的文件的日期/時間用戶的機器(例如,客戶端),你比下降專有的路徑(的ActiveX —其他唯一的選擇上這將是一個非常不愉快的用戶使用許多用戶在山上跑步的警告經驗 —閃存等)是相對較新的,未得到廣泛支持的File API,它提供了lastModifiedDate
。但是,您必須再次檢測瀏覽器是否支持它,然後將這些信息包含在單獨的(例如,隱藏的)字段中。實際上,這取決於你的觀點:Firefox,Chrome和Opera在最近的版本中支持它(Firefox很長一段時間,這是他們的想法) 。 Apparently IE目前還不支持它,即使在IE9中(我沒有親自驗證過)。
這裏是讀書的最後修改日期(live copy)粗糙但很完整的例子:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Show File Modified</title>
<style type='text/css'>
body {
font-family: sans-serif;
}
</style>
<script type='text/javascript'>
function showFileModified() {
var input, file;
// Testing for 'function' is more specific and correct, but doesn't work with Safari 6.x
if (typeof window.FileReader !== 'function' &&
typeof window.FileReader !== 'object') {
write("The file API isn't supported on this browser yet.");
return;
}
input = document.getElementById('filename');
if (!input) {
write("Um, couldn't find the filename element.");
}
else if (!input.files) {
write("This browser doesn't seem to support the `files` property of file inputs.");
}
else if (!input.files[0]) {
write("Please select a file before clicking 'Show Modified'");
}
else {
file = input.files[0];
write("The last modified date of file '" + file.name + "' is " + file.lastModifiedDate);
}
function write(msg) {
var p = document.createElement('p');
p.innerHTML = msg;
document.body.appendChild(p);
}
}
</script>
</head>
<body>
<form action='#' onsubmit="return false;">
<input type='file' id='filename'>
<input type='button' id='btnShowModified' value='Show Modified' onclick='showFileModified();'>
</form>
</body>
</html>
你在哪裏上傳使用什麼方法的文件? –