Jump to content

Calling All Files From A Different Directory Located Above Domain Name Directory


fizshoemaker

Recommended Posts

Hi all

 

I am attempting to create a script in PHP which reads and includes all files from a directory which is above the domain name directory.

 

For example:

  • My domain name is example.com and located in /var/www/html/example.com/ and I want /var/www/html/example.com/file.php to be able to read from:
    • /var/www/html/videos/video1/ which contains index.html and the folders:
      • /var/www/html/videos/video1/images/ and /var/www/html/videos/video1/scripts/

    [*]If I use include (/var/www/html/videos/video1/index.html) it will only call the html file, which is done perfectly. However all the files in images folder and the scripts folders are not able to load.

I don't want to copy or call each file separately. I want to be able to only need to call index.html and then make the browser think it's in that directory and automatically read any file within there.

 

I know this works because Moodle uses this method (in file.php) to protect learning files by storing them in a moodledata folder which is one level above the public folder.

I've had a look but cannot make sense of it and I've searched the Internet to achieve the method I have explained above but have not had any success.

 

The reason I want to do this is to avoid having duplicate video files on the server for other sites that are hosted on the same server.

Many thanks in advance and for taking the time to assist.

Edited by fizshoemaker
Link to comment
Share on other sites

The HTTP request that the browser makes must be to a publicly accessible .php file that then reads the actual file and outputs it with the correct content-type header followed by the contents of the file. The actual file id/name is specified on the end of the url as a GET parameter (file.php?id=123 or via url rewriting (somepath/123)

Link to comment
Share on other sites

The HTTP request that the browser makes must be to a publicly accessible .php file that then reads the actual file and outputs it with the correct content-type header followed by the contents of the file. The actual file id/name is specified on the end of the url as a GET parameter (file.php?id=123 or via url rewriting (somepath/123)

 

Thanks for the prompt response.

 

What if it was:

  • www.example.com/file.php?dir=/var/www/html/videos/video1/index.html

Is this what you mean? I have tried this and able to include index.html but the problem is that it won't include the images and scripts files. Is this something to do with the content-type?

Edited by fizshoemaker
Link to comment
Share on other sites

If you are using Apache, you might have a look at the Alias (and Directory) directives for the configuration files. This is how the default installation makes the Apache documentation available from the local server without putting the files in your document root.

 

Otherwise, any file you want from that "protected" directory must be read by a script in the publicly accessible area and passed through to the browser. That also means that all links in the "protected" files to other "protected" files must use the same approach.

 

And, for the record, I advise against putting the entire path name in the url. This gives hackers some information about your server that your really do not want them to have. I would use something like getimage.php?file=imagefile.jpg&chapter=1 and then have the getimage.php script decide how to build the full path.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.