Jump to content

Random Picture Display


DeanHensler

Recommended Posts

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.php

Looking for some help here.  Website is www.SWMORacing.com and the folder with the images is going to be www.swmoracing.com/forums/Banners

Link to comment
https://forums.phpfreaks.com/topic/22816-random-picture-display/
Share on other sites

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!
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.