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.