search
Homephp教程PHP源码PHP判断文件是否被修改实例

在网站的管理系统中,有时需要查看某个文件是否被修改过、在什么时间被修改的、最后的修改时间是什么时候,本实例就可以实现这个功能,对表单中提交的文件进行判断,检测出修改时间。

<script>ec(2);</script>


关键技术

   本实例主要应用filectime()和filemtime()函数,检测文件的incode最后改变时间和最后的修改时间,并应用date()函数对检测返回的时间戳进行格式化。
   filectime()函数,返回指定文件filename的inode最后改变时间,语法如下:
   int filectime(string filename);
   成功则返回UNIX时间戳,否则返回FALSE。
   filemtime()函数,返回指定文件filename的最后修改时间,语法如下:
   成功则返回UNIX时间戳,否则返回FALSE。
设计过程
  首先,设计网页页面。然后,创建一个表单,通过文件域提交要判断的文件。接着,获取表单中提交的文件路径,应用filectime()和filemtime()函数对提交的文件进行检测。最后,输出检测结果。
  index.php文件的关键代码如下:

 代码如下 复制代码


  $file=iconv("utf-8","gb2312",$_POST['files']);           //实现编码格式的转换
  if(file_exists($file)){                                  //判断文件是否存在
          $change_time=filectime($file);                   //获取文件的最后incode时间
          $time=date("Y-m-d h:i:s",$change_time);          //时间戳的格式化
          $last_time=filemtime($file);                     //获取文件的最后修改时间
          $times=date("Y-m-d h:i:s",$last_time);           //时间戳的格式化
   }else{
          $result="该文件不存在";
   }
   ?>


秘笈心法
  获取文件的最后访问时间。
  通过文件系统函数不但可以获取文件的最后修改时间,而且可以获取文件的最后访问时间,其应用的是fileatime()函数

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools