可以';t通过下载脚本访问Alias目录中的文件


Can't access file in Alias-directory via download-script

我正在开发一个下载脚本atm。php文件位于xamp-htdocs目录中,而包含这些文件的文件夹位于外部HDD上。

我已经为外部驱动器设置了别名:

<Directory "h:/Filme">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory> 
Alias /filme "H:/Filme"

这是下载脚本:

<?php
$download_dir = "filme/";
$files = array(
                "1" => "300.avi",
                "2" => "asdf.txt",
                "3" => "doc.pdf",
                "4" => "bild3.jpg",
              );
$file = $download_dir.$files[$_GET['id']];
header("Content-Type: x-type/subtype");
header("Content-Length: ".filesize($file));
header("Content-Disposition: attachment; filename=".$files[$_GET['id']]);
readfile($file);
?> 

下载通过以下方式开始:

<a href="download.php?id=2">asdf.txt</a><BR>

现在,问题如下:我可以通过在浏览器的地址栏中键入localhost/filme/asdf.txt来访问文件,例如asdf.txt。然而,我可以使用下载脚本下载的文件显示:

 <br />
<b>Warning</b>:  filesize(): stat failed for filme/asdf.txt in <b>C:'Program Files'xampp'htdocs'download.php</b> on line <b>26</b><br />
<br />
<b>Warning</b>:  readfile(filme/asdf.txt): failed to open stream: No such file or directory in <b>C:'Program Files'xampp'htdocs'download.php</b> on line <b>32</b><br />

老实说,我不知道如何修复这个O.O

TY表示答案等<3

HTTP和文件系统中的路径结构有区别。PHP对定义的HTTP访问别名一无所知。

您必须以文件系统能够理解的方式定义文件的路径。这可能意味着使用

$download_dir = "H:/Filme/";