php - 无法使用 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");
谁能看到我可能做错了什么?
解决方案
尝试这个:
$txt = "truthisgod";
$fileAppend= file_put_contents('customers2.txt', $newCustomer.PHP_EOL , FILE_APPEND | LOCK_EX);
推荐阅读
- django - Django:shell plus --print-sql 如果查询很长,则显示不完整的 sql
- node.js - 无法在heroku中使用socket io
- ruby-on-rails - rails ckeditor 无法生成模型来存储上传的文件
- python - 糟糕的预测,但良好的模型准确性
- asp.net-web-api - 混合 IdentityServer4 和 WebAPI .net 4.5.2
- java - 在 Java 中使用合并排序对链接列表进行排序
- php - 图像保存为 tmp 文件
- wordpress - 如何修复 WordPress 中的这些 404 错误?
- android - 在 cordova/phonegap Android 应用程序上关闭屏幕后媒体停止播放
- python - 正则表达式向后匹配任何内容,直到第一次出现字符串