如果你在谈论的文件的日期/时间用户的机器(例如,客户端),你比下降专有的路径(的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>
你在哪里上传使用什么方法的文件? –