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

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


ฟังก์ชัน tmpfile() ใช้สร้าง ไฟล์ชั่วคราว (temporary file) ที่มีชื่อเฉพาะตัว (unique) ไฟล์จะถูกลบอัตโนมัติเมื่อปิด (fclose) หรือจบสคริปต์ ส่งคืน file pointer สำหรับไฟล์ใหม่, หรือ FALSE เมื่อล้มเหลว

ไวยากรณ์ (Syntax)

tmpfile()

พารามิเตอร์ (Parameters)

  • ไม่มีพารามิเตอร์

ค่าที่ส่งคืน (Return Value)

ส่งคืน file pointer ของไฟล์ชั่วคราวใหม่, หรือ FALSE เมื่อล้มเหลว

ตัวอย่างการใช้งาน

<?php
$tmpfile = tmpfile();
fwrite($tmpfile, "This is demo text in temp file!");
rewind($tmpfile);
echo fread($tmpfile, 1024);
fclose($tmpfile);
?>

ผลลัพธ์

This is demo text in temp file!