fileatime 함수

함수 fileatime는 파일의 마지막 액세스 시간을 Unix 타임스탬프로 반환합니다. 매개변수로 파일 경로를 전달합니다. 파일이 존재하지 않으면 함수는 false를 반환합니다.

구문

phpfileatime(string $filename): int|false

예제

파일의 마지막 액세스 시간을 가져옵니다:

php<?php
  $res = fileatime('test.txt');
  echo $res;
?>

코드 실행 결과:

php1672531200

예제

액세스 시간을 가져오기 전에 파일 존재 여부를 확인합니다:

php<?php
  $filename = 'nonexistent.txt';
  if (file_exists($filename)) {
    echo fileatime($filename);
  } else {
    echo 'File not found';
  }
?>

코드 실행 결과:

php'File not found'

예제

Unix 타임스탬프를 읽기 쉬운 형식으로 변환합니다:

php<?php
  $timestamp = fileatime('test.txt');
  echo date('Y-m-d H:i:s', $timestamp);
?>

코드 실행 결과:

php'2023-01-01 00:00:00'

함께 보기

  • 수정 시간을 반환하는 함수 filemtime
  • 생성 시간을 반환하는 함수 filectime
  • 액세스 시간을 변경하는 함수 touch