Hi PHP builders!
I am working on a script for browsing apache directory listing. I am probably what some would refer to as a ”script kid”, so I was thinking about posting this at the beginners board but because of the advanced nature of my script I decided to post it here.
I am working on further developing a script that I got from a friend. The script displays files and folders with a bit of eye candy and some useful file information. I am not satisfied with it thou because I want to integrate an image gallery function that displays thumbs of images. Since the original script is written with perl and black magic I don’t stand the slightest chance to be able to implement this function into the perl script. Because of that I am going to take the best aspect of my friends script and make a new one in PHP. The most beautiful aspect of the perl-script is that it works together with apache ”rewrite” and is run on all folders on my www directory structure. That is, I don’t have to put the script in each and every single folder to make the script run if I point my browser to a specific folder (and believe me I have allot of folders, so that simply wouldn’t work!).
To be able to do this the script uses apache(?) global variables such as SCRIPT_URL and SCRIPT_URI.
The part of the perl-script that utilize these variables looks like this. I hope it gives some idea what it does with them even without being a native perl freak (and I myself am faaaar from that).
%data = &GetData();
if( defined($ENV{'SCRIPT_URL'}) ) { # Where are we?
$data{'dir'} = $ENV{'SCRIPT_URL'};
if( ($data{'dir'} !~ /\/$/) || ($ENV{'REQUEST_URI'} ne '/') ) {
$data{'dir'} = $ENV{'REQUEST_URI'};
$data{'dir'} =~ s/^\/(browse\.cgi)?\??//;
$data{'dir'} =~ s/\/\/$/\//;
if( $data{'dir'} eq '' ) { $data{'dir'} = '/'; };
};
};
&Browse($data{'dir'});
I spoke with the owner of http://demon.hell.org.pl/ who has written a very neat PHP-script for browsing apache directory listings. It has the ability to show images as thumbs and does more or less exactly what I want – however it has to be executed in the same folder as your browser is pointing at. He agreed to send me a copy of his script to use (for myself, at least in this stage).
My mission now is to implement those global variables the perl-script uses into this PHP-script . Since I am not experienced in PHP programming I don’t know how to go about this.
I want a function in my PHP-script that is similar to the perl code above. In other words I want to change a PHP-script that is normally run from a ”static” directory to be able to receive a global variable like SCRIPT_URL, look at that directory and output its ”enhanced” listing like it usually does (but for the SCRIPT_URL instead of the ”/.” url as it does in current state).
The script is to be run from the www-root as my current perl-script does. The reason this works is because I am using the mod_rewrite module for apache2.
My mod_rewrite configuration is set up like this:
RewriteEngine on
RewriteCond %{REQUEST_URI} -d
RewriteRule /$ /browse.cgi
And because of those few lines apache2 runs /browse.cgi (from www-root), while feeding it with REQUEST_URI so that browse.cgi knows what folder to output. In theory it should be rather simple to just run the PHP-script instead of browse.cgi. But the problem is, and now I am repeating myself I guess, is that the PHP-script doesn’t have a function for receiving a global variable like that.
So my questions goes out to the great community of PHP builders. What would a function like that look like? Anyone done anything similar to this that could help me out? I would be VERY grateful for any help on this.
Its really a very cool project and I would be happy share it once its done. The Rewrite module is kinda magic, it allows for so many opportunities its amazing!