FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


showing off the code I just made and ask for suggestions





Mgccl
showing off the code I just made and ask for suggestions
This is the code that randomly select an picture file(you define) and show it!... can be used on forums!
any one have any feature requests? because I think I got nothing need to upgrade
Code:
<?php
$url[] = "a.jpg";
$url[] = "b.gif";
$url[] = "c.png";
$rand = array_rand ($url);
$file = $url[$rand];
$path = pathinfo ($file);
switch ($path['extension']) {
case "jpg";
header ( "Content-Type: image/jpeg" );
break;

case "gif";
header ( "Content-Type: image/gif" );
break;

case "png";
header ( "Content-Type: image/png" );
break;
}
readfile ($file);
?>
n0obie4life
You sure it works?

Doesn't seem correct.
rohan2kool
firstly, the arrays are not declared properly. the function array_rand will always return c.png. Instead declare the array as:

Code:

$url = array("a.jpg", "b.gif", "c.png");

//or you can also declare as:

$url = array();
$url[0] = "a.jpg";
$url[1] = "b.gif";
$url[2] = "c.png";


Rest everything is alright.
Mgccl
in PHP5 it don't need $url = array(); because my book said nothing about that...
I think it is needed in lower version of PHP, but looks like add that line won't hurt
rohan2kool
you don't need that in any php versions. It's just a good practice. It tells the php parse which kind of variable it has to handle hence thereby giving you an advantage on the memory side.

[edit]

I am extremely sorry.. but your code is 100% correct. When you use $myarray[] = somevalue , the somevalue is actually appended to the array.. so ur code is completely correct. Sorry for that.

rohan
Related topics
Show off corner
Getting page could not be displayed
Don't Use Flash
THE CREATORS SITE: Time to show off
So is everyone here using HTML coding???
Beatles
help with php needed
Mod Projects lots of info
why i am not so sure about reigion
Etiquettes For Seekers of Knowledge - Islam
Outrageous: Denmark re-publish Mohammud cartoons
How does one ask a girl out?
Explain what the Holy Spirit is???
Are sins real?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.