Random Image Selector

~bk

I
Political Access
Joined
3 Nov 2003
Messages
3,768
<?php
// Random image selector
srand( time() );
$files = array();
if ($dir = @opendir("./images/logos/")) {
while (($file = readdir($dir)) !== false) {
if ( eregi( '.(jpeg)$', $file ) ) {
$files[] = $file;
}
}
closedir($dir);
}
$file = $files[rand() % sizeof( $files )];
// Old code used to generate the image, rather than pick it.
// header( "Content-Type: image/jpeg" );
// header( "Content-Length: " . filesize( $file ) );
// readfile( $file );
print "<img src=\"images/logos/$file\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />";

?>

Can anyone tell me where I am wrong? I'm totally new at this. I took this code from SPeedY_B's source with his permission. The problem is that the images aren't loading.
 
I'm going to use it on my site. Is that what you ask for?
 
I don't know if I'm supposed to post this :p but here's the source.

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>bk.ganai.com [v2.0]</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="icon" href="images/misc/bk.png" type="image/png" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<meta name="description" content="bk.ganai.com [v2.0]" />
<meta name="keywords" content="bilal karim, Bilal Karim, bilal, karim, ~bk, BilalKarim, bk, ganai, Bilalkarim, images, links, wallpapers, walls, shoutbox, about, icons, music, movies, games, palm, sony, vaio, sony vaio, Canada, canada, Honda, Hondahsc, last samurai, Links, google, xbox, penny arcade, penny-arcade, xbox, little-gamers, little gamers, microsoft, Google, matrix, matrix reloaded, matrix revolutions, shahrukh khan, cars"/>
<meta name="robots" content="ALL" />
<meta content="5 Days" name="revisit-after" />
<meta name="author" content="Bilal Karim" />
<meta content="Copyright (c) 2003 Bilal Karim" name="copyright" />
</head>
<body>
<center>

<br />

<?php
// Random image selector
srand( time() );
$files = array();
if ($dir = @opendir("./images/logos/")) {
while (($file = readdir($dir)) !== false) {
if ( eregi( '.(jpeg)$', $file ) ) {
$files[] = $file;
}
}
closedir($dir);
}
$file = $files[rand() % sizeof( $files )];
// Old code used to generate the image, rather than pick it.
// header( "Content-Type: image/jpeg" );
// header( "Content-Length: " . filesize( $file ) );
// readfile( $file );
print "<img src=\"images/logos/$file\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />";

?>


<br /> <br />

<table class="body">
<tr>
<td class="right">

<center><b><u>Chat:</u></b></center>
<br /><br />

<iframe name="shoutbox" src="http://bk.ganai.com/shoutbox/floodbox.php" width="670px" height="100px" frameborder="0"></iframe>
</td>
</tr>
</table>
<br />

<table class="body">
<tr>
<td class="info">
<center><b>Current Mood:</b> <img src="images/smilies/cool.gif" height="20px" width="20px" alt= "coo!"/> &nbsp;&nbsp; &nbsp; &nbsp;
<b>Game of the Month:</b> ESPN NHL 2004 &nbsp;&nbsp; &nbsp; &nbsp;
<b>Quote of the Month:</b> "Life Means More..."
</center>

</td>
</tr>
</table>
<br />

<table class="body">
<tr>
<td class="header">
<b>Testing...</b> | <i>Sunday May 23, 2004</i>
</td>
</tr>
<tr>
<td>
<br />
<p>
Testing 1 2 3...
</p>

</td>
</tr>
</table>



<br />
<table>
<tr>
<td class="nav" valign="top"><div style="text-align:center;">&nbsp;&nbsp;<a href="index.html">Main</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="walls.html">Wallpapers</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="desktops.html">Desktop</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="archives.html">Archives</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="links.html">Links</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="about.html">About</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="contact.html">Contact</a></div></td>
</tr>
</table>
<center><img src="images/misc/div.jpg" height="1px" width="370px" alt="div" /></center>

Best viewed in Mozilla Browser - 1024x768 <br />
Site design, content, and coding &copy; 2003-2004 Bilal Karim


</center>
</body>
</html>
 
what does the php code output? this line

print "<img src=\"images/logos/$file\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />";

PS: There is no such thing as XHTML 1.1 Transitional ;)
 
j79zlr said:
PS: There is no such thing as XHTML 1.1 Transitional ;)

My cousin told me about it. :p
We'll talk about that later.

j79zlr said:
what does the php code output? this line

print "<img src=\"images/logos/$file\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />";

What do you mean by that?
 
I mean when you load the webpage what is the output of the code; i.e.

<img src="images/logos/somepic.jpg" alt="loading" class="noborder" title="bk.ganai.com" />
 
It's this, I think:

<img src="images/logos/logo.jpg" height="203px" width="700px" alt="bk.ganai.com logo"/>
 
PHP:
<?php
// Random image selector
srand( time() );
$files = array();
if ($dir = @opendir("./images/logos/")) {
 while (($file = readdir($dir)) !== false) {
  if ( eregi( '.(jpeg)$', $file ) ) {
   $files[] = $file;
  }
 }
closedir($dir);
}
$file = $files[rand() % sizeof( $files )];
print "<img src=\"./images/logos/$file\" alt=\"loading\" title=\"bk.ganai.com\" />";
?>

That should work?

Also as j79zlr said, transitional doesn't exist, and get rid of all those keywords in the meta tag, they actually don't help search engines (decent ones) seeing as your page is scanned for it's content rather than the meta tags.. it's far too easy to lie about content in meta tags ;)
 
What i meant is, that i want a page to go to to see the code it generates so that we can see the output of the script, misspelled variables and whatnot can screw it up./

Also, your host has to support PHP.
 
SPeedY_B said:
PHP:
<?php
// Random image selector
srand( time() );
$files = array();
if ($dir = @opendir("./images/logos/")) {
 while (($file = readdir($dir)) !== false) {
  if ( eregi( '.([B]jpeg[/B])$', $file ) ) {
   $files[] = $file;
  }
 }
closedir($dir);
}
$file = $files[rand() % sizeof( $files )];
print "<img src=\"./images/logos/$file\" alt=\"loading\" title=\"bk.ganai.com\" />";
?>

That should work?

Also as j79zlr said, transitional doesn't exist, and get rid of all those keywords in the meta tag, they actually don't help search engines (decent ones) seeing as your page is scanned for it's content rather than the meta tags.. it's far too easy to lie about content in meta tags ;)


I will remove those tags soon. Would it matter if I change jpeg to jpg?
 
X-Istence said:
What i meant is, that i want a page to go to to see the code it generates so that we can see the output of the script, misspelled variables and whatnot can screw it up./

Also, your host has to support PHP.

My host does support PHP. Here's the page. Hope it helps.
http://bk.ganai.com/test/main.html
 
Doh, try using main.php not main.html :p
 
Yeah, change it to jpg.. that may be your problem as it's outputting

Code:
<img src="images/logos/" alt="loading" class="noborder" title="bk.ganai.com" />

lacking the file.
 
well its working, but its not. :)

Try this

PHP:
print "<img src=\"images/logos/" . $file . "\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />";
 
The print part works (I have it on my page) however its searching for .jpeg files, and bk has (I gather) .jpg... so I'm guessing he needs to just change that part.
 
ok, last post :D

you need to change the images/logos to point to the doc root, since you are in ./main, and your jpegs are jpg's

PHP:
<?php
// Random image selector
srand( time() );
$files = array();
if ($dir = @opendir("./images/logos/")) {
while (($file = readdir($dir)) !== false) {
  if ( eregi( '.(jpg)$', $file ) ) {
   $files[] = $file;
  }
}
closedir($dir);
}
$file = $files[rand() % sizeof( $files )];
print "<img src=\"/images/logos/$file\" alt=\"loading\" title=\"bk.ganai.com\" />";
?>
 
Just that or should I replace that line with the old one?
 
I'm not sure if the variable is parsed in print, with the above, if that doesn't work, replace with

PHP:
print "<img src=\"/images/logos/" . $file . "\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />";
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back