首页 > 解决方案 > 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);
}

标签: phpfile

解决方案


非常愚蠢的错误,尝试下载不同的文件并且它有效。然后我意识到文件的名称是 driver.txt。所以 PHP 正在寻找 driver.txt.txt。我感谢所有的帮助。


推荐阅读