DeanHensler Posted October 3, 2006 Share Posted October 3, 2006 I'm an ASP guy and trying to learn PHP here and there. I've got a phpbb forum that I run and I need to start selling advertising via a banner at the top. I want to put the banners in a directory and have the php page randomly display images from that directory. I checked out this page for information on how to do it, but I'm not getting any images displayed.http://www.phpfreaks.com/quickcode/Random-Picture-Display/98.phpLooking for some help here. Website is www.SWMORacing.com and the folder with the images is going to be www.swmoracing.com/forums/Banners Quote Link to comment Share on other sites More sharing options...
printf Posted October 3, 2006 Share Posted October 3, 2006 It would be better to create an array of the files you have, then select a random key from that array. Then anytime you add more banners you update that array. It's so much better than reading a directory every time the page loads! If you want example tell me and I will make you one!me! Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 3, 2006 Share Posted October 3, 2006 without seeing your version of the code, a few things jump to mind:[code=php:0]$file_dir="pics/a10";[/code] could be a problem. you could add [code=php:0]if(!is_dir($file_dir)) echo "not a directory";[/code] behind that line to make sure your variable validates as a directory.[code=php:0] $extension=substr($file,-6);[/code] assumes the provided extension is six characters long. so if you're just putting ".jpg" as the extension, it probably wouldn't work. Try this instead:[code=php:0] $extension=substr($file,-strlen($f_type));[/code]the PHP manuel reports that the read_dir method used in the tutorial is not correct. Their recommendation would look like this: [code=php:0]while (false !== ($file = readdir($dir))) [/code]If those don't fix it, some specific error messages PHP is providing would certainly help narrow things down. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.