Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3487540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:09:41+00:00 2026-05-18T11:09:41+00:00

I have downloaded and added this very simple, one file, php web file explorer

  • 0

I have downloaded and added this very simple, one file, php web file explorer system(called Indexer) to my XAMPP server.

My XAMMP server is on my C: drive, but I want Indexer to display a directory on my G: drive. But when I change (what I think are) the right configuration variables, it doesn’t work properly.

Here is the code I think is to do with the problem:

// configuration  
$Root = realpath("G:/test");  
$AllowDownload = TRUE;  
$WebServerPath = dirname("G:/test");

and later on in the code…

elseif ($AllowDownload) {  

        echo "<a href=\"http://".getenv("SERVER_NAME").$WebServerPath."/$rel_path".$item["filename"]."\">".$item["name"]."</a>";
    }

This is what happens: The script does correctly display the contents of the “test” directory on the G: drive, but when I click the filename, to download/view the file, the link is broken because the php constructs the link wrong (I suppose).
The link looks like this: http://localhostg//%5Bname of file].

Would you know how to solve this problem?

This script works perfectly if I change the configuration variables so it displays the contents of a relative subdirectory. And it also says $Root variable can be located outside the webserver root.

Also, even though clicking the link doesn’t work, right-clicking and selecting “Save Target As” allows me to save/download the file.

(Feel free to ask if you need more information) 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:09:42+00:00Added an answer on May 18, 2026 at 11:09 am

    Your web server can not see the files outside the DocRoot, so it can not serve the files via the browser with direct links. You need to print their contents into the browser with readfile() with the headers properly set.

    To make this work, you need to change the configuration in indexer.php:

    // this way it works with accentuated letters in Windows
    $Root = utf8_decode("G:\test"); // define the directory the index should be created for (can also be located outside the webserver root)
    
    $AllowDownload = TRUE; // enclose file items with the anchor-tag (only makes sense when the files are in the webserver root)
    // you need to place download.php in the same directory as indexer.php
    $WebServerPath = dirname($_SERVER['SCRIPT_NAME']) . "/download.php?path="; // path where the indexed files can be accessed via a http URL (only required when $AllowDownload is TRUE)
    

    And you have to place a new file called download.php in the same directory as indexer.php, with this content:

    <?php
    
    // it must be the same as in indexer.php
    $Root = utf8_decode("G:\test");
    
    function checkFileIsInsideRootDirectory($path, $root_directory) {
        $realpath = realpath($path);
    
        if (!file_exists($realpath))
            die("File is not readable: " . $path);
    
        // detects insecure path with for example /../ in it
        if (strpos($realpath, $root_directory) === false || strpos($realpath, $root_directory) > 0)
            die("Download from outside of the specified root directory is not allowed!");
    }
    
    function forceDownload($path) {
        $realpath = realpath($path);
    
        if (!is_readable($realpath))
            die("File is not readable: " . $path);
    
        $savename = (basename($path));
    
        header("Pragmaes: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private", false);
        header("Content-type: application/force-download");
        header("Content-Transfer-Encoding: Binary");
        header("Content-length: " . filesize($path));
        header("Content-disposition: attachment; filename=\"$savename\"");
    
        readfile("$path");
        exit;
    }
    
    if (!isset($_GET['path']))
        die("Path not specified!");
    
    $fullPath = $Root . $_GET['path'];
    
    checkFileIsInsideRootDirectory($fullPath, $Root);
    
    forceDownload($fullPath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have downloaded Orca to edit an MSI file. I want to remove some banner
I have downloaded the silver light from this http://www.microsoft.com/silverlight// I need to use this
I have a python application that relies on a file that is downloaded by
I have 2 SQLite databases, one downloaded from a server ( server.db ), and
I have downloaded a font that looks less than desirable if it is not
I have downloaded Privoxy few weeks ago and for the fun I was curious
Does anybody use the Class Designer much in Visual Studio? I have downloaded the
I'm new to Apex and have just downloaded Eclipse to get to work Eclipse
We have a number of PDFs hosted using Lighttpd but when they are downloaded
I'm trying to parse an Atom feed programmatically. I have the atom XML downloaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.