ฟังก์ชัน fileatime
ฟังก์ชัน fileatime ส่งคืนเวลาเข้าถึงไฟล์ล่าสุดในรูปของ Unix timestamp ต้องส่งพาธไปยังไฟล์เป็นพารามิเตอร์ ถ้าไฟล์ไม่มีอยู่ ฟังก์ชันจะส่งคืน 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 timestamp เป็นรูปแบบที่อ่านได้:
<?php
$timestamp = fileatime('test.txt');
echo date('Y-m-d H:i:s', $timestamp);
?>
ผลลัพธ์จากการรันโค้ด:
'2023-01-01 00:00:00'