Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Hàm fileatime() trong PHP


Hàm fileatime() trả về thời gian truy cập cuối (last access time) của file dưới dạng Unix timestamp. Trả về FALSE nếu lỗi.

Cú pháp

fileatime(file_path)

Tham số

  • file_path – Đường dẫn file.

Giá trị trả về

Trả về Unix timestamp lần access cuối. FALSE nếu lỗi.

Ví dụ 1: Timestamp

<?php
echo fileatime("new.txt");
?>

Kết quả

1315416291

Ví dụ 2: Định dạng ngày giờ

<?php
echo "Last access time of the file: " . date("F d Y H:i:s", fileatime("new.txt"));
?>

Kết quả

Last access time of the file: September 22 2018 11:23:52

Lưu ý: Trên nhiều filesystem, atime không cập nhật mỗi lần đọc (tối ưu hiệu năng). Kết quả bị cache.