How to get the modified time of a file being uploaded in JavaScript?

前端 未结 3 1889
礼貌的吻别
礼貌的吻别 2020-12-01 17:43

Is there ever a way possible to get the actual creation / modification time of the file being uploaded, using JavaScript?

As for PHP, using filectime() a

3条回答
  •  一整个雨季
    2020-12-01 18:02

    If you're talking about the file date/time on the user's machine, you can get that via the File API (support), which provides lastModified, which is the date/time as a number of milliseconds since The Epoch (if you want a Date, you can pass that into new Date). (There's also the deprecated lastModifiedDate, but that is deprecated and not supported on Safari [at least].) The File API is universally supported in modern browsers (the particular feature you'd be using is the File object). You'd get the value from the File object and include that information in a separate (for instance, hidden) field.

    Here's a rough-but-complete example of reading the last modified date (live copy):

    
    
    
    
    Show File Modified
    
    
    
    
    

    The reason you couldn't get the time from the uploaded file on the server is that only the content of the file is transmitted in the request, not the client's filesystem metadata.

提交回复
热议问题