Hello everyone.
I am clueless when it comes to php. I am using the script below to call my images.
my image links look like chimage.php?southington=imagename.gif
what i am trying to do is modify this script to allow me to use multiple directories. As the code sits right now, i can only direct the script to one directory. ($imagedir)
is there a way to make it so i can use multiple directories?
and call my images like so.
chimage.php?southingon=imagename.gif
chimage.php?bristol=imagename.gif
chimage.php?waterbury=imagename.gif
and
?southingon= will point to the directory images/southington
?bristol= will point to the directory images/bristol
?waterbury= will point to the directory images/waterbury
etc. . .
do you get what i am trying to say? im sure its very simple, but like i said, when it comes to php i wouldnt even be considered a newb. I come before that. :p
Thanks for your help!
<?
// ---------------- CONFIGURABLE SECTION -----------------
// Please modify the following or it will not work on
// your website.
// Where did you actually put your images?
// Make sure that the path you put below ends with
// a directory slash ("/"). The script below assumes it.
$imagedir = "/path/to/image/dir/goes/here/" ;
// What are the websites (hostnames) that can use this
// image?
// If your site can be accessed with or without the
// "www" prefix, make sure you put both here. Do not put
// any trailing slashes ("/") nor any "http://" prefixes.
// Follow the example below.
$validprefixes = array (
"yoursite.com",
"www.yoursite.com"
) ;
// What is the main page of your website? Visitors will
// be directed here if they type
// "http://www.yourdomain.com/chimage.php"
// in their browser.
$homepage = "http://www.yoursite.com/" ;
// ------------ END OF CONFIGURABLE SECTION ------------
// --- YOU NEED NOT MODIFY ANYTHING AFTER THIS LINE ---
function isreferrerokay ( $referrer, $validprefixes )
{
$validreferrer = 0 ;
$authreferrer = current( $validprefixes );
while ($authreferrer) {
if (eregi( "^https?://$authreferrer/", $referrer )) {
$validreferrer = 1 ;
break ;
}
$authreferrer = next( $validprefixes );
}
return $validreferrer ;
}
//----------------------- main program -----------------------
$image = $_GET['southington'] ;
$referrer = getenv( "HTTP_REFERER" );
if (isset($_GET['southington'])) {
if (empty($referrer) ||
isreferrerokay( $referrer, $validprefixes )) {
$imagepath = $imagedir . $image ;
$imageinfo = getimagesize( $imagepath );
if ($imageinfo[2] == 1) {
$imagetype = "gif" ;
}
elseif ($imageinfo[2] == 2) {
$imagetype = "jpeg" ;
}
elseif ($imageinfo[2] == 3) {
$imagetype = "png" ;
}
else {
header( "HTTP/1.0 404 Not Found" );
exit ;
}
header( "Content-type: image/$imagetype" );
@readfile( $imagepath );
}
else {
header( "HTTP/1.0 404 Not Found" );
}
}
else {
header( "Location: $homepage" );
}
?>
-Dave