上传时获取原始文件创建日期
我们有一个将文件上传到我们网站的流程。 对于用户来说,能够看到这些文件的创建时间变得很重要。 我正在寻找一种从 HttpPostedFile 中提取原始创建日期的方法。 如果有人对我有想法,我会非常感激(此时我有点困惑)。
We have a process in place that uploads files to our website. It has become important to the users to be able to see when those files were created. I'm looking for a way to extract the original create date from the HttpPostedFile. If anyone has an idea for me I'd really appreciate it (I'm a bit stumped at this point).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我尝试了上面提到的布莱恩提到的方法,但它给了我不正确的日期。 即 1600 年左右。
不过,您可以通过 FileUpload 控件的 files 属性从“lastModifiedDate”属性获取每个(待)上传文件的日期。
这是它的 HTML/Javascript 示例。
我取自:
http://www.w3schools.com/jsref/ tryit.asp?filename=tryjsref_fileupload_files
并根据我们的需要对其进行了一些修改。 注意:请阅读下面这个 HTML /Javascript 片段之后我的评论。
例如,您可以使用 jQuery 文件上传控件将此信息作为附加参数传递。
以下是演示这一点的链接:
jquery 文件上传模块发送额外参数
I tried the approach mentioned by Bryon above but it gives me incorrect date. i.e something around year 1600.
You can however get the Date for each (to be) uploaded file from the 'lastModifiedDate' property via FileUpload control's files property.
Here is the sample HTML/Javascript for it.
I have taken it from:
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_fileupload_files
and modified it a bit for our need. Note: Please read my comment below after this HTML /Javascript snippet.
You can pass this information as an additional parameter using jQuery file upload control for example.
Here is the link demonstrating this:
jquery file upload module sending extra parameter
您无权访问在客户端上创建文件的日期。 您可以使用 Fiddler 来验证这一点。 我相信您看到的唯一数据是文件名和 MIME 类型。
You don't have access to the date the file was created on the client. You can use Fiddler to validate this. I believe the only data you'll see being posted is the filename and the mime type.
这是我最终得到的解决方案。 上传文件并将其保存到服务器后,您可以访问文件中的元数据(但是,此解决方案当前仅适用于图像文件 - 那里还有一些额外的代码可用于显示整个元数据如果需要的话,该文件,并且我在我破解的元数据中发现了一些奇怪的日期格式,这可能可以做得更干净)...
Here's the solution I ended up with. Once you've uploaded the file and saved it to the server you can access the metadata in the file (this solution however, only currently applies to image files - there's also some extra code in there that could be used to show the entire metadata for the file if needed, and I found some weird date formating in the metadata that I hacked around that could probably be done cleaner)...
您只需从 HttpPostedFile::FileName 获取文件系统创建日期即可。
像这样的事情:
You just grab the file system creation date from the HttpPostedFile::FileName.
Somthing like this: