如何获取在JavaScript/PHP中上传文件的修改时间? [英] How to get the modified time of a file being uploaded in JavaScript/PHP?

查看:146
本文介绍了如何获取在JavaScript/PHP中上传文件的修改时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


是否有办法使用JavaScript/PHP获取实际创建/修改上传文件的时间?

至于JavaScript,我已经研究了很多,尝试了很多代码,但是没有运气(也许试图在不可能的情况下做可能的事情).

对于PHP,使用 filectime()和 filemtime(),它仅显示文件上传的日期/时间,而不显示文件实际创建/修改的时间.在源头上.

简而言之,我想要的是在上载之前/之中/之后检查文件的m时间(尽可能),并确定是否将文件存储在服务器上,并将其报告给客户端.

如果您需要的话,这是我整理的HTML/JavaScript代码的一个片段....

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

As for JavaScript, I have researched a lot, tried quite a few codes, but to no luck (perhaps trying to do possible out of impossible).

As for PHP, using filectime() and filemtime(), it only shows the date / time the file is uploaded, and not the time the file is actually created / modified on the source.

In short, what I want is to check the m-time of a file before/during/after upload (where-ever possible) and decide whether or not to store the file on the server, and report the same back to the client.

In case you need, here is a snap of HTML/JavaScript code that I fiddled with....

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Experiments</title>
        <script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
        <script type="text/javascript">
            function _do(){
                return true;
            }

            function getLastMod(){
                var myFrm = document.getElementById('myIframe');
                var lastModif = new Date(myFrm.contentWindow.document.lastModified);
                return lastModif.toLocaleString();
            }

            function ShowTempImage(imagePath){
                $("#test").html("<b>Before</b> " + getLastMod());
                $("iframe#myIframe").attr("src",imagePath);
                $("#test").html($("#test").html());
                $("#LastModified").html("<b>Before</b> " + getLastMod());
            }
        </script>
    </head>
    <body>
        <form action="" method="post" enctype="multipart/form-data" onsubmit="return _do()">
            <input type="text" id="txtTest" name="Text" />
            <input type="hidden" id="hidTest" name="Hidden" value="Some value" />
            <input type="file" id="uplTest" name="File" onchange='ShowTempImage(this.value);' />
            <input type="submit" value="Submit" />
        </form>
        Test Value: <span id="test"></span>
        <br />
        Last Modified Date : <span id="LastModified"></span>
        <iframe id="myIframe" onload="" src="C:\\xampp\htdocs\\experiments\\DSC03425.JPG" style="display:block; width: 800px; height: 400px;"></iframe>
        <img src="file:///C:/xampp/htdocs/experiments/DSC03425.JPG" />
    </body>
</html>



请帮忙.......

在此先感谢



Any help please.......

Thanks in advance

推荐答案

(#test").html("<​​span class =" code-keyword>< b > 之前< > " + getLastMod());
("#test").html("<b>Before</b> " + getLastMod());


("iframe#myIframe" ).attr("src",imagePath);
("iframe#myIframe").attr("src",imagePath);


(#test").html(
("#test").html(


这篇关于如何获取在JavaScript/PHP中上传文件的修改时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆