PHP checks whether the file is modified.

Source: Internet
Author: User


Key technologies

This example mainly uses the filectime () and filemtime () functions to detect the last change time and last modification time of the incode of the file, and uses the date () function to format the timestamp returned by the detection.
The filectime () function returns the last inode change time of the specified file filename. The syntax is as follows:
Int filectime (string filename );
If the operation succeeds, the UNIX timestamp is returned. Otherwise, FALSE is returned.
The filemtime () function returns the last modification time of the specified file filename. The syntax is as follows:
If the operation succeeds, the UNIX timestamp is returned. Otherwise, FALSE is returned.
Design process
First, design the webpage. Then, create a form and submit the file to be judged through the file field. Then, obtain the file path submitted in the form, and use the filectime () and filemtime () functions to detect the submitted file. Finally, the detection result is output.
The key code of the index. Php file is as follows:

The code is as follows: Copy code


<? Php
$ File = iconv ("UTF-8", "gb2312", $ _ POST ['Files']); // converts the encoding format
If (file_exists ($ file) {// checks whether the file exists.
$ Change_time = filectime ($ file); // Obtain the last incode time of the object
$ Time = date ("Y-m-d h: I: s", $ change_time); // format the timestamp
$ Last_time = filemtime ($ file); // get the last modification time of the object
$ Times = date ("Y-m-d h: I: s", $ last_time); // format the timestamp
} Else {
$ Result = "this file does not exist ";
   }
?>


Tips
Obtain the last object access time.
The file system function not only obtains the last modification time of the file, but also obtains the last access time of the file. The fileatime () function is used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.