Need help with this bit of code please
Posted: Sun Jan 14, 2007 6:24 am
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello, I'm a total rookie at this. I have a script which generates a random image from a file ( of images uploaded by my forum users) . It works fine except one user uploads a .png image with all of his posts and its' showing up too frequently. I thought I had the script pulling just jpg and jpeg images but for some reason this .png shows up. I'm trying to modify the code to block or at least limit this .png image from showing up. The file is also 541 bytes(?) if that helps. My code is below. Please let me know how I should modify this...thanks!Code: Select all
<?php
Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
Header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
Header("Pragma: no-cache");
Header("Content-Type: image/jpg");
Header("Content-Type: image/jpeg");
$dir = "forums/uploads/images"; // This is the folder where the images are
srand((double)microtime()*1000000);
$i = 0;
$dirHandle = opendir($dir); // Open the images folder
while(($im = readdir($dirHandle)))
{
if($im != ".." && $im != ".") // Don't read in the 2 folders ".." and "."
{
$image[$i] = $im; // Select an image
$i++;
}
}
closedir($dirHandle); // Close the folder
$n = rand(0,(count($image)-1));
if(!readfile($dir."/".$image[$n])) // Read the image
readfile($dir."error/error.gif"); // If the script can't find the directory, display this image
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]