关于php:文件下载权限被拒绝读取文件

file download permission denied to read the file

我正在使用php readfile函数忽略提供服务器上文件的完整直接url。但是,它仅显示错误而不是下载文件,并显示failed to open stream: No such file or directory in。但是,该文件位于指定的目录中。

我尝试下载的文件是由用户上传的(即我认为是httpd进程,它将是所有者)。但是以下代码显示无法打开文件-

1
2
3
4
5
6
7
8
9
10
$full_path = $row['full_path'];
            $file_name = $row['file_path'];
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header('Content-Type: application/pdf');
            header("Content-Type: application/force-download");
            header("Content-Disposition: attachment; filename="".$file_name.""");                

            readfile($full_path);

该目录的默认权限设置为755,我正在下载的文件也将权限显示为755。我无法理解这里的问题。

编辑:服务器是hostgator。

编辑:header(" Location:$ full_path")工作正常,所以我认为它与路径无关。

编辑:$full_path看起来像-uploads/abc.pdf,而$file_path看起来像abc.pdf

文件结构:

1
2
3
4
--root
  downloader.php
      ---uploads
         abc.pdf


看到我对OP的评论确实解决了这一问题...

我:

"what does var_dump(); reveal? make sure there's no whitespace introduced anywhere also. I'm kind of baffled at this point. Fred -ii-"

OP:

"WTF, there was a whitespace at the end in the string. I am really sorry for this, I never checked for that. Thanks to all of you guys... a€" codeomnitrix"

我:

trim() would have fixed that in a jiffy

咨询:http://php.net/manual/en/function.trim.php