sven Posted April 1, 2004 Posted April 1, 2004 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
gamehead200 Posted April 1, 2004 Posted April 1, 2004 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!
sven Posted April 1, 2004 Author Posted April 1, 2004 (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 websiteEDIT: got it<?php$quotes = file("bumper/names.txt");$quote = rand(0, sizeof($quotes)-1);$file = $quotes[$quote];echo "<img src=\"bumper/$file\">";?> Edited April 1, 2004 by sven
gamehead200 Posted April 1, 2004 Posted April 1, 2004 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!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now