• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Random Image Selector

~bk

I
Political User
#1
<?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.
 

~bk

I
Political User
#4
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>
 

j79zlr

Glaanies script monkey
Political User
#5
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 ;)
 

~bk

I
Political User
#6
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?
 

j79zlr

Glaanies script monkey
Political User
#7
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" />
 

~bk

I
Political User
#8
It's this, I think:

<img src="images/logos/logo.jpg" height="203px" width="700px" alt="bk.ganai.com logo"/>
 

SPeedY_B

I may actually be insane.
#9
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 ;)
 

X-Istence

*
Political User
#10
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.
 

~bk

I
Political User
#11
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?
 

SPeedY_B

I may actually be insane.
#15
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.
 

j79zlr

Glaanies script monkey
Political User
#16
well its working, but its not. :)

Try this

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

SPeedY_B

I may actually be insane.
#17
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.
 

j79zlr

Glaanies script monkey
Political User
#18
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\" />";
?>
 

j79zlr

Glaanies script monkey
Political User
#20
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

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,240
Members
89,015
Latest member
loxioalix