fizshoemaker Posted December 30, 2012 Share Posted December 30, 2012 (edited) 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 December 30, 2012 by fizshoemaker Quote Link to comment https://forums.phpfreaks.com/topic/272518-calling-all-files-from-a-different-directory-located-above-domain-name-directory/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 30, 2012 Share Posted December 30, 2012 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) Quote Link to comment https://forums.phpfreaks.com/topic/272518-calling-all-files-from-a-different-directory-located-above-domain-name-directory/#findComment-1402190 Share on other sites More sharing options...
fizshoemaker Posted December 30, 2012 Author Share Posted December 30, 2012 (edited) 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 December 30, 2012 by fizshoemaker Quote Link to comment https://forums.phpfreaks.com/topic/272518-calling-all-files-from-a-different-directory-located-above-domain-name-directory/#findComment-1402191 Share on other sites More sharing options...
fizshoemaker Posted December 31, 2012 Author Share Posted December 31, 2012 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/272518-calling-all-files-from-a-different-directory-located-above-domain-name-directory/#findComment-1402308 Share on other sites More sharing options...
DavidAM Posted December 31, 2012 Share Posted December 31, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/272518-calling-all-files-from-a-different-directory-located-above-domain-name-directory/#findComment-1402353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.