我正在尝试下载一个文件,我已经上传到我的uploads文件夹。目录如下:
xampp
> htdocs
> myProject
> normal_user
> displayfile.php <-- my current location
> uploads
> myfile.pdf这是显示文件名的HTML代码的一部分:
```` The download code below is able to be executed BUT it didn't download the intended file. Instead, it downloads a .PHP `file name: uploads` with `file type: All Files:
`
```javascriptif (isset($_GET['forcedownload'])) { $filepath = "M:/xampp/htdocs/myProject/uploads/" . $row_file['f_name']; // return: myfile.pdf if (file_exists($filepath)) { header('Content-Description: File Transfer'); header('Content-Type: ' . $row_file['f_type']); //return: application/pdf header('Content-Disposition: attachment; filename="'.basename($filepath).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filepath)); flush(); // Flush system output buffer readfile($filepath); exit(); } else { exit(); }}`
我已经看过许多教程,也回答了与我的情况相似的堆栈溢出问题,但情况仍然一样。我不知道我错过了什么。
发布于 2021-06-15 08:05:54
echo $filepath;要查看此变量的值,请执行以下操作。
它可能不应该满足您想要下载的文件的名称。
https://stackoverflow.com/questions/67981989
复制相似问题