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
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!
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.