php - PHP 读取文件 - 未完成
问题描述
我正在尝试读取文本文件,文件名基于变量。
<?php
$todaydate = date("Y-m-d");
$lines = file("/news/$todaydate.txt");
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
?>
这是我得到的错误:
PHP Warning: file(/news/2020-08-04.txt): failed to open stream: No such file or directory in /home/dev/proj1/readinsert.php on line 3
我 100% 确定该文件存在。:) 我犯了什么基本错误?
解决方案
我会删除路径开头的 / 并使用相对路径
另外,尝试使用 getcwd 和 file_exists 获取更多信息
推荐阅读
- python - 在 Numpy 中生成唯一的随机值
- r - 您如何使在 AWS 上运行的 R 编码程序可从您的网站访问?
- development-environment - 需要:用于轻松切换开发环境的程序
- android - 检索intent.extra.getLong(“KEY”,我必须在这里填写什么值)时我必须填写什么值
- google-analytics - 在 google tag manager 中,我们如何使用 staging 和 live 环境将数据发送到不同的 Google Analytics 帐户
- mongodb - 失败:无法在分片系统上进行完全恢复 - 首先从转储目录中删除“config”目录
- python - 我应该在类文档字符串中列出类方法吗?
- mysql - 在 SQL Server 中插入忽略多个值
- paypal - 如何为没有 Paypal 的客户集成 Paypal?
- jquery - 在 JQuery 中重新启动动画