简体   繁体   English

目录下载链接不起作用“服务器错误404-找不到文件或目录。”

[英]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.

相关问题 codeignaiter 404-找不到文件或目录。 在实时服务器上 - codeignaiter 404 - File or directory not found. on live server Cakephp:404 - 在Windows服务器上部署后找不到文件或目录 - Cakephp : 404 - File or directory not found after deploying on the windows server 404-找不到文件或目录。 您正在寻找的资源可能已被删除,名称已更改或暂时不可用 - 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable Nginx服务器laravel路由目录404错误 - Nginx server laravel route directory 404 error Opendir错误; 找不到这样的文件或目录 - Opendir error; No such file or directory found 404-移至新服务器时,wordpress中找不到文件或目录重定向问题 - 404 - File or directory not found redirect issue in wordpress when moving to new server 使用PHP将文件下载到我的服务器目录 - Download a file to my server directory using PHP 下载已上传到mysql的文件到服务器目录 - Download file which was upload to mysql to server directory 找不到文件上传的浏览按钮404文件目录 - Browse button for file upload 404 file directory not found 使用Codeigniter在服务器中没有错误的文件或目录 - Error no such file or directory in server with Codeigniter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM