How to modify file modification time in php

藏色散人
Release: 2023-03-07 08:26:01
Original
3756 people have browsed it

php method to modify file modification time: first create a PHP sample file; then use "touch("test.txt",mktime(19,5,10,10,26,2013));" Just re-modify the modification time of the specified file.

How to modify file modification time in php

Recommended: "PHP Video Tutorial"

The modification time and access time of the file can be changed through php touch() The function sets the access and modification times of the specified file.

php touch(filename,time,atime)
Copy after login

Syntax

Parameter description:

filename required. Specifies the files to be contacted.

time Optional. Set time. The default is the current system time.

atime Optional. Set access time. The default is the current system time.

Attempts to set the access and modification times of the file given by filename to the specified time. If the optional time parameter is not set, the current system time is used. If the third parameter atime is given, the access time of the specified file will be set to atime .

Returns true if successful and false if failed.

Case:

Change the last modification time of test.txt to 19:05:10 on October 26, 2013

<?php
touch("test.txt",mktime(19,5,10,10,26,2013));
?>
Copy after login

Attachment: How to get the file creation time and modification time in PHP:

filemtime (string filename)

Returns the time when the file was last modified, Returns FALSE on error. The time is returned as a Unix timestamp, usable with date().

For example: $a=filemtime("log.txt");

echo "Modification time:".date("Y-m-d H:i:s",$a);

filectime (string filename)

Returns the time when the last inode of the file was modified, or FALSE if an error occurs. The time is returned as a Unix timestamp.

For example: $a=filectime("log.txt");

echo "Creation time:".date("Y-m-d H:i:s",$a);

fileatime (string filename)

Returns the time when the file was last accessed, or FALSE if an error occurs. The time is returned as a Unix timestamp.

For example: $a=fileatime("log.txt");

echo "Modification time:".date("Y-m-d H:i:s",$a);

The above is the detailed content of How to modify file modification time in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template