Web Development

การอ่านเขียนไฟล์ใน PHP

03 มกราคม 20231 นาที
0
การอ่านเขียนไฟล์ใน PHP
Table of Contents

Method

  • fopen() flag r, w, a (read, write, append)
  • fread() ต้องระบุขนาดไฟล์
  • fwrite() ต้องระบุข้อความที่จะเขียน
  • fclose() ปิดไฟล์

Open file

PHP Logo
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");

Read file

PHP Logo
echo fread($myfile,filesize("webdictionary.txt"));

Write file

PHP Logo
$txt = "John Doe\n"; fwrite($myfile, $txt);

Append file

PHP Logo
$txt = "Jane Doe\n"; fwrite($myfile, $txt);
Tags:PHP

คลิกเพื่อแสดงความคิดเห็น