(PHP 4, PHP 5)
touch — 設定文件的訪問和修改時間
說明
bool touch ( string$filename
[, int $time
= time()
[, int $atime
]] )
嘗試將由 filename
給出的文件的訪問和修改時間設定為給出的 time
。
注意訪問時間總是會被修改的,不論有幾個參數。
如果文件不存在,則會被創建。
參數
filename
要設定的文件名。
time
要設定的時間。如果沒有提供參數 time
則會使用當前系統的時間。
atime
如果給出了這個參數,則給定文件的訪問時間會被設為
atime
,否則會設置 為time
。如果沒有給出這兩個參數,則使用當前系統時間。
返回值
成功時返回 TRUE
, 或者在失敗時返回 FALSE
。
更新日志
版本 說明 5.3.0 能夠修改 Windows 下目錄的最后修改時間。
范例
Example #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;
}
?>
Example #2 使用 time
參數的 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';
}
?>
注釋
Note:
注意:不同文件系統對時間的判斷方法可能是不相同的。
Warning在 PHP 5.3.0 之前無法修改 Windows 下目錄的最后修改時間。