Xcalibur Posted February 11, 2002 Share Posted February 11, 2002 can someone program me a random image php script? i dont want one i can download from a site.. i just want a simple one, without all the fancy stuff... and something around like 1 or 2 kb. Link to comment Share on other sites More sharing options...
0 gregor Posted February 11, 2002 Share Posted February 11, 2002 tested, works like hell ;) <?php $path = "."; // path to your directory $arr = array (); if ($dir = @opendir($path)) { while ($file = readdir($dir)) { if ($file != "." && $file != ".." && is_file($file)) $arr[] = $file; } closedir($dir); } // -> enable this if you want to see all files in your directory //for ($i = 0; $i < count ($arr); $i++) // echo $arr[$i] ." n"; // show random file from your directory echo $arr[rand (0, count ($arr)-1)]; ?> oh,.. i forgot,.. the size of this script is 517 bytes :p Link to comment Share on other sites More sharing options...
0 Weasel Posted February 11, 2002 Share Posted February 11, 2002 Here's the code that puts the random image in my sig: <? //Random image generator //Author: Weasel - www.almostsmart.com $URL1="images/design/sig/small_logo.gif"; $URL2="images/design/sig/small_logo2.gif"; srand((double) microtime() * 1000000); if(rand(1,2) == 1) @header ("Location: $URL1"); else @header ("Location: $URL2"); ?> I put that in sig.html on my server (there cant be any white space outside the code). Then in my sig field I put <pre> [I.MG]http://www.almostsmart.com/sig.html[/I.MG] </pre> Link to comment Share on other sites More sharing options...
0 Xcalibur Posted February 11, 2002 Author Share Posted February 11, 2002 thank you so much weasel.. your script works... except i have to put a php extension to it..otherwise my server doesnt recognise it for some reason..but it works.. thanks so much.. i needed it for a sig too :D and for your script gregor.. it doesnt work.. this is what happens: http://www.netjunk.org/xcalibur/sigs/test.php and also, it doesnt filter out just the image files... thanks anyway... Xcalibur Link to comment Share on other sites More sharing options...
0 gregor Posted February 11, 2002 Share Posted February 11, 2002 Xcalibur,... i didn't know you did want that kind of stuff.. my functionjust prints the name of img file to the browser.. if you want a rand script for images.. it's like this: <?php $path = "."; // path to your directory $arr = array (); if ($dir = @opendir($path)) { while ($file = readdir($dir)) { if ($file != "." && $file != ".." && is_file($file) && (strrchr ($file, ".") == ".gif" || strrchr ($file, ".") == ".jpg")) $arr[] = $file; } closedir($dir); } // -> enable this if you want to see all files in your directory //for ($i = 0; $i < count ($arr); $i++) // echo $arr[$i] ." n"; // show random file from your directory @header ("Location: ". $arr[rand (0, count ($arr)-1)] .""); ?> this script will show you a file if it is jpg or in gif format. Link to comment Share on other sites More sharing options...
0 Xcalibur Posted February 12, 2002 Author Share Posted February 12, 2002 Originally posted by Weasel Here's the code that puts the random image in my sig: <? $URL1="images/design/sig/small_logo.gif"; $URL2="images/design/sig/small_logo2.gif"; srand((double) microtime() * 1000000); if(rand(1,2) == 1) @header ("Location: $URL1"); else @header ("Location: $URL2"); ?> I put that in sig.html on my server (there cant be any white space outside the code). Then in my sig field I put <pre> [I.MG]http://www.almostsmart.com/sig.html[/I.MG] </pre> hey weasel.. how would you use that script if you have more than 2 images? i tried to fool around with the script, but no luck.. i suck at php.. lol also, that script works gregor.. thanks a lot :D Link to comment Share on other sites More sharing options...
0 gregor Posted February 12, 2002 Share Posted February 12, 2002 no prob ;) Link to comment Share on other sites More sharing options...
0 Sleeper Veteran Posted February 13, 2002 Veteran Share Posted February 13, 2002 so if im reading this right i can use Gregor's script and i can call it by telling my sig to call <pre>[IMG= [url]www.myspace.com/mysigs/sigs.htm[/url] ] </pre> And thanks for the script:) Link to comment Share on other sites More sharing options...
0 Sleeper Veteran Posted February 13, 2002 Veteran Share Posted February 13, 2002 after trying this it did not work....... do i need to save the file as .php or should .htm work? also does the host where i am keeping the file have to support php scripting? Thanks :) Link to comment Share on other sites More sharing options...
0 gregor Posted February 13, 2002 Share Posted February 13, 2002 that depends of your servers settings. try to save the script in php! it should work! Link to comment Share on other sites More sharing options...
0 Sleeper Veteran Posted February 13, 2002 Veteran Share Posted February 13, 2002 I managed to get a host that supports php, but for some reason it is not showing the different images, it just loads the sameone every time.... anyideas i copied the code exactly so what am i doing wrong? <?php $path = "."; // path to your directory $arr = array (); if ($dir = @opendir($path)) { while ($file = readdir($dir)) { if ($file != "." && $file != ".." && is_file($file) && (strrchr ($file, ".") == ".gif" || strrchr ($file, ".") == ".jpg")) $arr[] = $file; } closedir($dir); } // -> enable this if you want to see all files in your directory //for ($i = 0; $i < count ($arr); $i++) // echo $arr[$i] ." n"; // show random file from your directory @header ("Location: ". $arr[rand (0, count ($arr)-1)] .""); ?> Thanks Link to comment Share on other sites More sharing options...
Question
Xcalibur
can someone program me a random image php script? i dont want one i can download from a site.. i just want a simple one, without all the fancy stuff... and something around like 1 or 2 kb.
Link to comment
Share on other sites
10 answers to this question
Recommended Posts