This script was sent in by Pete Holiday.
What this script does is make it easier for you to have pop up images on your site. Instead of writing the code for a new pop up window each time, this little snippet of PHP will basically write that code for you.
(I should probably note that there are a quite few different ways to do this, but this is an interesting use of PHP)
Create a file called "showpic.php" with this code in it and place it in your images directory:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>Display Image</title></head>
<body style="background-color : #000000; color : #FFFF90; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 12px; margin : 0px 0px 0px 0px;">
<img src="<?=$img?>">
</body>
</html>
Then, put this function at the top of your pages, or even better, if there's an included file you're already using, put it in that so you have access to it.
<?
function popup_image($filename) {
// put the path to your images folder below.
$prefix = '/images/';
//put the path to the showpic.php file below
$showpic = '/images/showpic.php';
@$img_info = getimagesize($prefix . $filename);
// the window.open needs a name for the window, and it can't have certain characters. This parsing is for that.
// If you use a static text string for the name, it will try to open every image into the same window (without resizing)
$f2 = str_replace('.', ", $filename);
$f2 = str_replace(' ', ", $f2);
if ($img_info != null) {
$h = $img_info[1]; $w = $img_info[0];
return "<a href=\"#\" onclick=\"javascript:window.open('$showpic?img=$filename', 'ShowImg_$f2', 'directories=0, height=$h, location=0, resizable=0, scrollbars=0, toolbar=0, width=$w'); return false;\">";
}
}
?>
Then when you want to do a pop up image, put this on your page:
<? echo(popup_image('puppies.jpg') . 'My dog' . '</a>'); ?>
where 'puppies.jpg' is the name of your picture, and 'My dog' is the text you want to have linked, that will open the popup window.
See the demo for this here
You can also download the script here.