Jump to content

Recommended Posts

Posted

im having a problem getting this to use the correct line from the text file.

<?php

$quotes = file('bumper/names.txt');
$quote = array_rand($quotes);

$joke = wordwrap($quotes[$quote]);
$joke = explode("\n", $joke);



echo "<img src=\"bumper/$joke\" width=\"250\" height=\"40\">";

?>

the problem is that it wont return the right answer. the funny thing is it works in my sig and its an almost direct copy. any ideas? see the result of the script here


Posted

That will definetely not work...

See here: http://forums.invisionpower.com/index.php?...13&

This code should work:

<?php
$dh = opendir(".");
while (false !== ($file = readdir($dh)))
{
if (preg_match('/\.jpg$/i', $file) and $file != "avatar.png") // scanning for .jpg files only and stopping avatar.jpg being loaded (you will run into errors if this isnt here)
{
   $filelist[] = $file;
}
}

srand((double)microtime()*1000000);
$picnum = rand(0, sizeof($filelist) - 1);

header("Location: " . $filelist[$picnum]);

closedir($dh);
?>

Just replace the .jpg with the file extension you need to use. Leave avatar.png as is, and name the file avatar.png. Put all your images in one directory! :)

Posted (edited)

yeah, i found that one already, thats not what i want. i want it to fill in the place $joke with the file name which it gets from the text file. unless you want me to put that code 4 times into my website

EDIT: got it

<?php
$quotes = file("bumper/names.txt");
$quote = rand(0, sizeof($quotes)-1);
$file = $quotes[$quote];

echo "<img src=\"bumper/$file\">";
?>

Edited by sven
Posted

Its so much easier just to make 4 different directories and put the images you want in what image and put the same code in each directory! :)

BTW, nice sig! :rolleyes:

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...