ferozsho Posted February 3, 2009 Share Posted February 3, 2009 Hi I'm new to PHP and just discovering how useful it is. What i am trying to do is each time a visitor comes to the site they see a different image, and the image are in [1,2,3,4,5] and with random image script its work fine. I want to display images depend on there Priority like ex: 4th Image has [High Priority] and its has to display every 3rd image , 4 time's on each refresh. ex:[ 1,2,3,4,4,4,4,5] like this same as 2 having [Medium] so the seq: will be [1,2,2,4,4,4,4,5]... so on Thanks in advance. The Code:: include("../admin/config.php"); $folder = '../admin/ramdamimg/'; $exts = 'jpg jpeg png gif'; $files = array(); $i = -1; // Initialize some variables if ('' == $folder) $folder = './'; $handle = opendir($folder); $exts = explode(' ', $exts); while (false !== ($file = readdir($handle))) { foreach($exts as $ext) { // for each extension check the extension if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive //check the status of file if($oRan->isActive($file)=='Show'){ $files[] = $file; // it’s good ++$i; } } } } closedir($handle); // We’re not using it anymore if($files[0]==''){ $imagename=$path["webroot"].'common/theme/Default/image/default.jpg'; } else { srand((double)microtime()*1000000); // seed for PHP < 4.2 $rand = mt_rand(0, $i); // $i was incremented as we went along $filename = $files[$rand]; $src_file = $folder.$filename; setcookie("f_na",$oRan->getLink($filename),time()+300); $fixside = 223; $fixside_h = 181; $dest_file= $path["docroot"]."_files/random/".$filename; $image_info = getimagesize($src_file); if (($image_info[0] > $fixside) || ($image_info[1] > $fixside_h)){ if(!is_dir($path["docroot"]."_files/random")){ mkdir($path["docroot"]."_files/random"); } if(!file_exists($dest_file)) { $oMMenu->resizeImage($src_file,$dest_file,$fixside,$fixside_h,"100","#ffffff"); } $imagename=$path["webroot"]."_files/random/$filename"; } else { $imagename=$path["webroot"]."ramdamimg/$filename"; } } header('Location: '.$imagename); Great site by the way. Link to comment https://forums.phpfreaks.com/topic/143584-solved-random-images-with-priority/ Share on other sites More sharing options...
MadTechie Posted February 3, 2009 Share Posted February 3, 2009 I am not 100% sure what you mean but i think your asking for a edit that allows you to display images in a predefined order ie 1,2,3,4,4,4,4,5 means image 1 then image 2 then image 3 then image 4 then image 4 then image 4 then image 4 then image 5 ? if so replace srand((double)microtime()*1000000); // seed for PHP < 4.2 $rand = mt_rand(0, $i); // $i was incremented as we went along $filename = $files[$rand]; with $f_pos = array(1,2,3,4,4,4,4,5); $pos=$f_pos[0]; if(!empty($_COOKIE['f_pos']) { $pos = $_COOKIE['f_pos']+1; } setcookie("f_pos",$pos,time()+600); $filename = $files[$pos]; Link to comment https://forums.phpfreaks.com/topic/143584-solved-random-images-with-priority/#findComment-753392 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.