gacon Posted November 15, 2006 Share Posted November 15, 2006 Please let me know what happen to this code, it works, but sometimes it does not when I refresh the page.Thank you very much.<?function fun($Directory){ $dir = opendir($Directory); $index = 0; while($imgfile=readdir($dir)) { if ($imgfile != "." && $imgfile!="..") { $imgarray[$index]=$imgfile; $index++; } } closedir($dir); $rand = rand(0,count($imgarray)-1); if($rand >= 0) { echo '<CENTER><img src="c/div/'.$imgarray[$rand].'"width="10%" height="2%">'; }}echo fun("c/div/");?>If I change the line below in red, then it does not work at all... I can not figure it out.Thank you very much.<?function fun($Directory){ $dir = opendir($Directory); $index = 0; while($imgfile=readdir($dir)) { if ($imgfile != "." && $imgfile!="..") { $imgarray[$index]=$imgfile; $index++; } } closedir($dir); $rand = rand(0,count($imgarray)-1); if($rand >= 0) { echo '<CENTER><img src="[color=red]$Directory'[/color].$imgarray[$rand].'"width="10%" height="2%">'; }}echo fun("c/div/");?> Link to comment https://forums.phpfreaks.com/topic/27319-load-random-images-from-a-directory/ Share on other sites More sharing options...
Orio Posted November 15, 2006 Share Posted November 15, 2006 Try:echo '<CENTER><img src="'.$Directory.$imgarray[$rand].'"width="10%" height="2%">';Orio. Link to comment https://forums.phpfreaks.com/topic/27319-load-random-images-from-a-directory/#findComment-124930 Share on other sites More sharing options...
gacon Posted November 15, 2006 Author Share Posted November 15, 2006 Thank you, Orio...It works great.. :'( Link to comment https://forums.phpfreaks.com/topic/27319-load-random-images-from-a-directory/#findComment-125053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.