Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน touch() ใน PHP


ฟังก์ชัน touch() ตั้งค่าการเข้าถึงและแก้ไขเวลาของไฟล์ คืนค่า TRUE เมื่อสำเร็จ หรือ FALSE เมื่อล้มเหลว

ไวยากรณ์

touch(filename, time, atime)

พารามิเตอร์

  • ชื่อไฟล์ − ตั้งชื่อไฟล์

  • เวลา − ตั้งเวลา ค่าเริ่มต้นคือเวลาของระบบปัจจุบัน

  • เวลา − ตั้งเวลาการเข้าถึง ค่าเริ่มต้นคือเวลาของระบบปัจจุบัน

คืนสินค้า

ฟังก์ชัน touch() ส่งคืนค่า TRUE เมื่อสำเร็จ หรือ FALSE เมื่อล้มเหลว

ตัวอย่าง

<?php
$myfile = "new.txt";
// changing the modification time to current system time
if (touch($myfile)) {
   echo ("The modification time of $myfile set to current time.");
} else {
   echo ("The modification time of $myfile can’t be updated.");
}
?>

ผลลัพธ์

The modification time of new.txt set to current time.

เรามาดูตัวอย่างกันต่อ

ตัวอย่าง

<?php
$myfile = "new.txt";
$set_time = time() - 28800;
// changing the modification time
if (touch($myfile, $set_time)) {
   echo ("The modification time of $myfile updated to 8 hrs in the past.");
} else {
   echo ("The modification time of $myfile can’t be updated.");
}
?>

ผลลัพธ์

The modification time of new.txt updated to 8 hrs in the past.