(PHP 4, PHP 5, PHP 7, PHP 8)
touch — 設(shè)定文件的訪問和修改時間
$filename,$time = time(),$atime = ?,$mtime = null,$atime = null
嘗試將由 filename
給出的文件的訪問和修改時間設(shè)定為給出的 mtime。
注意訪問時間總是會被修改的,不論有幾個參數(shù)。
如果文件不存在,則會被創(chuàng)建。
filename要設(shè)定的文件名。
mtime
要設(shè)定的時間。如果參數(shù) mtime 為 null,則會使用當(dāng)前系統(tǒng)的 time()。
atime
如果這個參數(shù)不是 null,則給定文件的訪問時間會被設(shè)為 atime。
否則會設(shè)置為 mtime。
如果兩個參數(shù)都是 null,則使用當(dāng)前系統(tǒng)時間。
| 版本 | 說明 |
|---|---|
| 8.0.0 |
mtime 和 atime
現(xiàn)在可以為空。
|
成功時返回 true, 或者在失敗時返回 false。
示例 #1 touch() 例子
<?php
if (touch($filename)) {
echo $filename . ' modification time has been changed to present time';
} else {
echo 'Sorry, could not change modification time of ' . $filename;
}
?>
示例 #2 使用 mtime 參數(shù)的 touch()
<?php
// This is the touch time, we'll set it to one hour in the past.
$time = time() - 3600;
// Touch the file
if (!touch('some_file.txt', $time)) {
echo 'Whoops, something went wrong...';
} else {
echo 'Touched file with success';
}
?>
注意:
注意:不同文件系統(tǒng)對時間的判斷方法可能是不相同的。