ok i donno why i get asked these questions, even though I tell people i've no idea wtf i'm doing
so can anyone help me to answer this?
Quote:
Here’s one for you:
I want to put a random screen shot up on the page as a thumbnail that changes with each page load/reload. What I’m hoping to do is just upload the pictures into a directory on the server and have a script just pull it. I’ve made some headway, but what is happening is when you click the thumbnail it just executes the script and the picture that gets enlarged is not the one that’s showing on the page.
Here is the PHP:
PHP Code:
<?php
$image_directory = '.';
$image_extension = array();
$image_extension['gif'] = 'image/gif';
$image_extension['jpg'] = 'image/jpeg';
$image_extension['jpeg'] = 'image/jpeg';
$image_extension['png'] = 'image/png';
$image = null;
if (substr($image_directory,-1) != '/') {
$image_directory = $image_directory.'/';
}
if (isset($_GET['image'])) {
$img_info = pathinfo($_GET['image']);
if (
isset( $image_extension[ strtolower( $img_info['extension'] ) ] ) &&
file_exists( $image_directory.$img_info['basename'] )
) {
$image = $image_directory.$img_info['basename'];
}
} else {
$fileList = array();
$handle = opendir($image_directory);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $image_extension[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$image = $image_directory.$fileList[$imageNumber];
}
}
if ($image!=null) {
$img_info = pathinfo($image);
$contents = 'Content-type: '.$image_extension[ $img_info['extension'] ];
header ($contents);
readfile($image);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$picture = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$bgcolor = imagecolorallocate ($picture, 255, 255, 255);
$font_color = imagecolorallocate ($picture, 0,0,0);
imagestring ($picture, 2, 5, 5, "IMAGE ERROR", $font_color);
imagepng ($picture);
imagedestroy($picture);
}
}
?>
This is what calls it on the page:
<img src="http://www.kinprecision.com/rimg/wallpaperama-generator.php" width = "175" height = "131"
This is what I tried to make it a thumbnail:
<a href="http://www.kinprecision.com/rimg/wallpaperama-generator.php" target="_blank"><img
src="http://www.kinprecision.com/rimg/wallpaperama-generator.php" width="175" height="131" border="0">
Thanks
Alan
|