Before we begin coding either option, there are a few global things we must create.
The first one being what file types you want the system to read, and which ones to ignore. The below code does just that.
CODE
$file_types = array(
'.gif',
'.jpg',
'.jpeg',
'.png',
'.bmp',
'.tiff'
);
Take note of the '.' in front of each file extension. If the dot is not included in front of the file extension, the extension won't be recognized later on in the script when $file_types is put to use.
The next thing we have to do is locate just where our script is, store the path in a variable. This will be used to forward our script to the image.
CODE
$path = './';
// Set the DocumentRoot:
$document = explode('/', $_SERVER['PHP_SELF']);
$path_use = '';
// Now destroy the Script-Name and create the $path_use variable:
for ($i = 0; $i <= (count($document)-2); $i++) {
if ($document[$i] != '') {
$path_use .= '/' . $document[$i];
}
}
$path_use .= '/';
// Set the url:
$domain = $_SERVER['HTTP_HOST'];
Alright, now your probably wondering what the middle chunk of that does. Well, $path = './' sets $path to the current directory. $_SERVER['PHP_SELF'] takes the path of to the script (ie. if your website is www.domain.com/folder/adv_rsig.php.php, $_SERVER['PHP_SELF'] is /folder/adv_rsig.php).
We take $_SERVER['PHP_SELF'] and use explode to make an array of each piece from $_SERVER['PHP_SELF']. Because we don't want the adv_rsig.php in our path (because we will eventually be forwarding the script to an image), we have to take it out.
To do this, we use a for loop, and count the total number of values in the array document. We have to subtract 2 from this array because one, an array starts at 0, and two, because we want to get rid of that last array value, adv_rsig.php. For each value it finds, it checks to make sure it's not empty, and if it isn't, it will append it to the $path_use variable. Don't believe that it works? Test that it works by echoing $path_use.
After the for loop, we add a trailing '/' to our path_use variable, so that when we forward it to an image, we won't have problems. Lastly, we store the domain into a variable $domain, for example, www.yoursite.com.
Whew! Done with that part! Yay, on to the actual fun stuff!