php - PHP说文件不存在
问题描述
现在很失落。该文档的文件路径是正确的,并且位于 echo 正在打印的目录中,但它一直说“找不到文件”。
$fileName = 'driver.txt';
$filePath = $_SERVER['DOCUMENT_ROOT']."/driver.txt";
echo $filePath;
if(!file_exists($filePath)){ // file does not exist
die('file not found');
} else {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$fileName");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
// read the file from disk
readfile($filePath);
}
解决方案
非常愚蠢的错误,尝试下载不同的文件并且它有效。然后我意识到文件的名称是 driver.txt。所以 PHP 正在寻找 driver.txt.txt。我感谢所有的帮助。
推荐阅读
- python-3.x - 将 apply() 从 Python2 移植到 Python3
- java - 如何在Java中按不同顺序(asc/desc)的多个字段对列表进行排序?
- swift - SwiftUI:从后台返回后激活显示时应用程序崩溃
- python - python string.whitespace中的空字符串
- sqlite - CakePHP 使用 Sqlite 而不是 Mysql
- macos - Hadoop 在启动时崩溃 - docker-compose (MacOS)
- arrays - 两个 1D numpy / torch 数组的特殊索引以生成另一个数组
- reactjs - Page 404 appears in all routes of React Router
- javascript - How to have a fallback like behavior for static export in Next.JS
- java - Are creational design patterns useless in Dependency Injection environment ( like SpringBoot)?