Hàm fileatime
Hàm fileatime trả về thời gian truy cập cuối cùng vào tệp dưới dạng Unix timestamp. Tham số truyền vào là đường dẫn đến tệp. Nếu tệp không tồn tại, hàm sẽ trả về false.
Cú pháp
fileatime(string $filename): int|false
Ví dụ
Lấy thời gian truy cập cuối cùng vào tệp:
<?php
$res = fileatime('test.txt');
echo $res;
?>
Kết quả thực thi mã:
1672531200
Ví dụ
Kiểm tra sự tồn tại của tệp trước khi lấy thời gian truy cập:
<?php
$filename = 'nonexistent.txt';
if (file_exists($filename)) {
echo fileatime($filename);
} else {
echo 'File not found';
}
?>
Kết quả thực thi mã:
'File not found'
Ví dụ
Chuyển đổi Unix timestamp sang định dạng dễ đọc:
<?php
$timestamp = fileatime('test.txt');
echo date('Y-m-d H:i:s', $timestamp);
?>
Kết quả thực thi mã:
'2023-01-01 00:00:00'