fileatime 함수
함수 fileatime는 파일의 마지막 액세스 시간을 Unix 타임스탬프로 반환합니다. 매개변수로 파일 경로를 전달합니다. 파일이 존재하지 않으면 함수는 false를 반환합니다.
구문
fileatime(string $filename): int|false
예제
파일의 마지막 액세스 시간을 가져옵니다:
<?php
$res = fileatime('test.txt');
echo $res;
?>
코드 실행 결과:
1672531200
예제
액세스 시간을 가져오기 전에 파일 존재 여부를 확인합니다:
<?php
$filename = 'nonexistent.txt';
if (file_exists($filename)) {
echo fileatime($filename);
} else {
echo 'File not found';
}
?>
코드 실행 결과:
'File not found'
예제
Unix 타임스탬프를 읽기 쉬운 형식으로 변환합니다:
<?php
$timestamp = fileatime('test.txt');
echo date('Y-m-d H:i:s', $timestamp);
?>
코드 실행 결과:
'2023-01-01 00:00:00'