10/10/2018, 11:41
Ghi dữ liệu trong PHP
Các bác cho em hỏi, em có đoạn code:
<?php
$path="text.txt";
$file=fopen($path, "w");
$write=fwrite($file,"Hello");
fclose($file);
?>
để ghi file.
tuy nhiên mỗi lần mở lại file php thì nó sẽ ghi đè lên nội dung mới, nếu giờ em muốn sau khi mở lại file .php nó sẽ ghi tiếp vào file text.txt thì làm như thế nào? các bác giúp vs, e cảm ơn.
<?php
$path="text.txt";
$file=fopen($path, "w");
$write=fwrite($file,"Hello");
fclose($file);
?>
để ghi file.
tuy nhiên mỗi lần mở lại file php thì nó sẽ ghi đè lên nội dung mới, nếu giờ em muốn sau khi mở lại file .php nó sẽ ghi tiếp vào file text.txt thì làm như thế nào? các bác giúp vs, e cảm ơn.
Bài liên quan
file_put_contents($file, "Hello", FILE_APPEND | LOCK_EX);
Code chưa test, bạn thử xem sao.