0

I am trying to use a subdomain to make an internal file browser on my site look flashier. My site is example.com. I have a directory at example.com/files/, with many various subdirectories. I want files.example.com to point internally to example.com/filebrowser/index.php?uri="files", which will print all the files and subdirectories in example.com/files/.

The file browser currently uses $_SERVER['DOCUMENT_ROOT'] (/examplehost/1234/) to construct the address of the directory to search and index, however when accessed via files.example.com, the root address includes /examplehost/1234/filebrowser/, causing a failure to find the directory.

How should this issue be solved without hardcoding a document root?

New contributor
user24261195 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
5
  • 1
    Remove the last directory from /examplehost/1234/filebrowser/? For instance with dirname(), like so: 3v4l.org/Y1RUr Commented Apr 21 at 15:31
  • I had hoped there might be a more portable option that this but perhaps I'm just being lazy. Commented Apr 21 at 15:51
  • more portable: use a configuration parameter whichs default value is $_SERVER['DOCUMENT_ROOT'] when unset. then set it to the correct value for the new site. it may appear as-if the error was in the beginning to use the DOCUMENT_ROOT for that, but this is not entirely true. the problem is/was to only use it. you can create simple configuration files in PHP as INI files and with parse_ini_file(). they are often more readable than JSON Text files. keep them out of the webroot (naturally, you likely know that writing a file-browser...)
    – hakre
    Commented Apr 21 at 17:34
  • and as you write .htaccess, IIRC you can set (apache) environment variables there and they populate into $_SERVER. but I have no apache at hand right away to double check and directly make an example.
    – hakre
    Commented Apr 21 at 17:39
  • Set up a separate VHost config and install there some file manger app ... buuut, I would strongly recommend against adding such functionality (it is a huge attack surface). You should use SSH to manage remote server instead.
    – tereško
    Commented Apr 23 at 7:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.