Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get the last modified date of a file before uploading?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.54k
    Comment on it

    Check last modified date of a file using Javascript :

    Most of the applications has the feature of upload files to the server. In some cases we need the metadata of a file like file created date or last modified date etc. In server side application there are several api's to get the image's metadata. But the case is how can we get the metadata at the client side using JavaScript.

    So the solution is HTML5. Yes HTML5 provides the very nice File api to deal with this kind of file processing. Some of the old browsers not supported this File api but almost all latest browser support.

     

    Example of getting last modified date of a file using JavaScript : In this example I will show you how you can get the last modified date of a file before uploading it to the server.

    <!DOCTYPE html>
    <html>
    <head>
    <script>
    function getLastModifiedDate() {
        var file = document.getElementById('myfile').files[0];
        if (file) {
           document.getElementById("lastModifyDate").innerHTML =  file.lastModifiedDate;
        }
    }
    
    </script>
    </head>
    <body>
    <input type=file id='myfile' onchange="getLastModifiedDate()"/>
    <p id="lastModifyDate"></p>
    </body>
    </html>

     

    Output :

    Wed Jan 20 2016 11:39:52 GMT+0530 (IST)

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: