touch 함수
(PHP 4, PHP 5, PHP 7, PHP 8)
touch — 파일 접근 및 수정 시간 설정
설명
touch(string $filename
, ?int $mtime
= null, ?int $atime
= null
): bool
filename
매개변수에 명명된 파일의 액세스 및 수정 시간을 mtime
에 지정된 값으로 설정하려고 시도합니다. 액세스 시간은 매개변수의 수에 관계없이 항상 수정됩니다.
파일이 없으면 생성됩니다.
매개변수
filename
- 터치되는 파일의 이름입니다.
mtime
- 터치 시간입니다.
mtime
이null
이면 현재 시스템 time()이 사용됩니다. atime
null
이 아니면 지정된 파일 이름의 액세스 시간이atime
값으로 설정됩니다. 그렇지 않으면mtime
매개변수에 전달된 값으로 설정됩니다. 둘 다null
이면 현재 시스템 시간이 사용됩니다.
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
변경 로그
버전 | 설명 |
---|---|
8.0.0 |
mtime 과 atime 은 이제 nullable입니다.
|
Examples
예제 #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
매개변수를 사용하는 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';
}
?>
노트
메모: 시간 해상도는 파일 시스템마다 다를 수 있습니다.