Jump to content


Photo

Random Picture Display


  • Please log in to reply
2 replies to this topic

#1 DeanHensler

DeanHensler
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 03 October 2006 - 01:30 AM

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



#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 03 October 2006 - 02:28 AM

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!

#3 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 03 October 2006 - 04:24 AM

without seeing your version of the code, a few things jump to mind:

$file_dir="pics/a10";
could be a problem. you could add
if(!is_dir($file_dir)) echo "not a directory";
behind that line to make sure your variable validates as a directory.

$extension=substr($file,-6);
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:
$extension=substr($file,-strlen($f_type));


the PHP manuel reports that the read_dir method used in the tutorial is not correct. Their recommendation would look like this:
while (false !== ($file = readdir($dir)))


If those don't fix it, some specific error messages PHP is providing would certainly help narrow things down.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users