tonto68 Posted January 14, 2007 Share Posted January 14, 2007 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. The other images (pics) are much larger sizes so maybe a line of code specifying a minimum file size would work. My code is below. Please let me know how I should modify this (please give step by step instructions because this is Greek to me)...thanks! My code is below:<?phpHeader("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 aresrand((double)microtime()*1000000);$i = 0;$dirHandle = opendir($dir); // Open the images folderwhile(($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 imagereadfile($dir."error/error.gif"); // If the script can't find the directory, display this image?> Link to comment https://forums.phpfreaks.com/topic/34154-random-image-generator-help-request/ Share on other sites More sharing options...
Orio Posted January 14, 2007 Share Posted January 14, 2007 [code]<?phpheader("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 aresrand((double)microtime()*1000000);$i = 0;$dirHandle = opendir($dir); // Open the images folderwhile(($im = readdir($dirHandle))){ if($im != ".." && $im != ".") // Don't read in the 2 folders ".." and "." { $ext = strtolower(strrchr($filename,".")); if($ext == ".jpg" || $ext == ".jpeg" || $ext == ".jpe") { $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?>[/code]I added a part that checks if the extension is jpg, jpe or jpeg.Orio. Link to comment https://forums.phpfreaks.com/topic/34154-random-image-generator-help-request/#findComment-160680 Share on other sites More sharing options...
tonto68 Posted January 14, 2007 Author Share Posted January 14, 2007 Thanks for your reply. I tried using the code you gave me but unfortunately all that shows up where the pic should go is a vertical line. Link to comment https://forums.phpfreaks.com/topic/34154-random-image-generator-help-request/#findComment-160723 Share on other sites More sharing options...
corillo181 Posted January 14, 2007 Share Posted January 14, 2007 you should try going with mysql. Link to comment https://forums.phpfreaks.com/topic/34154-random-image-generator-help-request/#findComment-160726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.