首页 > 解决方案 > 无法使用 PHP 附加文本文件

问题描述

我正在做一个 php 教程,但一个方面不起作用,我不知道为什么。

我可以确认我在 Apache 中确实拥有此文件夹的写入权限。文本文件的内容:
Harry Ginter, 8237 Barkwood Dr., Lexington, KY, 40501
Felicia Ginter, 8238 Barkwood Dr., Lexington, KY, 40501
Trinity Ginter, 8238 Barkwood Dr., Lexington, KY, 40501
Eva Coutermarsh, 8239 Barkwood 博士,肯塔基州列克星敦,40501

这是应该工作的超级简单脚本,但是当我回显文件时,内容不会改变:

$newCustomer = "\nMitzy Ginter, 8240 Barkwood Dr., Lexington, KY, 40501";
//Open a file to append to.  First create a handle:
$fileAppend = fopen("customers2.txt", "a");
fwrite($fileAppend, $newCustomer);
fclose($fileAppend);  //close file
echo "<br>Current file contents: " . file_get_contents("customers2.txt");

谁能看到我可能做错了什么?

标签: php

解决方案


尝试这个:

$txt = "truthisgod";
 $fileAppend= file_put_contents('customers2.txt', $newCustomer.PHP_EOL , FILE_APPEND | LOCK_EX);

推荐阅读