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

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function