[英]Directory Download Link not working “Server Error 404 - File or directory not found.”
I am working on an Intranet with a searchable document repository page. 我正在使用具有可搜索文档存储库页面的Intranet。 It uses some php to generate a list of documents in a directory and put them in a table. 它使用一些php生成目录中的文档列表,并将它们放在表中。 When I click the link in the second column it should download the document but instead shows an error page with the phrase "404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." 当我单击第二列中的链接时,它应该下载文档,但显示一个错误页面,显示短语“ 404-找不到文件或目录。您正在寻找的资源可能已被删除,名称更改或被删除。暂时不可用。”
I'm using Windows server 2012 r2 and ISS 7.5. 我正在使用Windows Server 2012 R2和ISS 7.5。
I double checked and the files are definitely in the correct directory. 我仔细检查过,文件肯定在正确的目录中。
Here's the code for the webpage. 这是该网页的代码。
<?php
function getFileList($dir)
{
$retVal = array();
if (substr($dir, -1) != "/") $dir .= "/";
// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
// skip hidden files
if($entry[0] == ".") continue;
if(is_dir("$dir$entry")) {
$filename = "$dir$entry";
$retval[] = array(
"title" => "$filename/",
"path" => filetype("$filename"),
"size" => 0,
"lastmod" => filemtime("$filename"));
} elseif(is_readable("$dir$entry")) {
$filename = "$dir$entry";
$retval[] = array(
"title" => "$entry",
"path" => "$filename",
"size" => filesize("$filename"),
"lastmod" => filemtime("$filename"));
}
}
$d->close();
return $retval;
}
?>
<?php
$dirlist = getFileList("docs");
print "<table id='myTable' border=\"1\">\n";
print "<thead>\n";
print "<tr class='header'><th>File Name</th><th>Link (click to download)</th><th>Size</th><th>Last Modified</th></tr>\n";
print "</thead>\n";
print "<tbody>\n";
foreach($dirlist as $file) {
print "<tr>\n";
print "<td>{$file['title']}</td>\n";
$path_parts = pathinfo($file['path']);
$path_noext = $path_parts['dirname'] . "/" . $path_parts['filename'];
$path_noext = str_replace(' ', '%20', $path_noext);
print "<td><a href=pdf_download.php?filename={$path_noext}>{$file['title']}</a></td>\n";
print "<td>{$file['size']}</td>\n";
$timestamp = date('F d Y h:i A', $file['lastmod']);
print "<td>{$timestamp}</td>\n";
print "</tr>\n";
}
print "</tbody>";
print "</table>";
?>
Try changing 尝试改变
print "<td><a href=pdf_download.php?filename={$path_noext}>{$file['title']}</a></td>\n";
Into 进入
print "<td><a href=\"pdf_download.php?filename={$path_noext}\">{$file['title']}</a></td>\n";
You didn't quote the actual href
part of the link. 您没有引用链接的实际href
部分。
I fixed it. 我修好了它。
Change this line: 更改此行:
print "<td><a href=pdf_download.php?filename={$path_noext}>{$file['title']}</a></td>\n";
To this: 对此:
print "<td><a href=docs/{$file['title']}>{$file['title']}</a></td>\n";
It couldn't find the files because the download link was pointed to the root directory not to the documents directory. 它找不到文件,因为下载链接指向的是根目录而不是文档目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.