【发布时间】:2011-12-14 10:58:58
【问题描述】:
我无法从“public_html”外部向用户上传文件,这是每个人都可以通过 http 访问的文件夹。前任。 / 之后的 www.website.com/everyhting 是 public_html。我相信你们都知道我指的是什么。
所以我有这个脚本应该从(服务器视角)/images/protected/ 读取文件(sample.pdf),但 PHP 找不到我的文件。我做错了吗?
<?php
$file = '/images/protected/sample.pdf';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
} else {
echo "404 - FILE NOT FOUND!<br />\n";
echo "File: $file";
}
?>
每次执行此脚本时,我都会得到 404 - FILE NOT FOUND!<br />\n 而不是文件下载。
【问题讨论】:
-
你确定那是正确的路径吗?一个名为“images”的目录会在根目录中,这似乎很奇怪。
-
httpd 进程是否有权查看或读取该文件?
-
他可能列出的是绝对网络路径,而不是绝对系统路径。
-
@Akke 你能登录到那个盒子并 cd 到“图像”目录并向我们展示
pwd的输出吗?
标签: php file download readfile public-html