Hello,
I am still trying fully grasp functions in php. I wrote a script that picks a random number between 1 and whatever number is entered when calling the function. I can echo the number it creates in the its function and then I call it to get the number echoed. I am trying to randomly display an image from a folder. But I can not call the variable and its really weighing me down because I want get the images size with getimagesize. I have tried global but its not working. Any help would be great.
Thanks so much
Here is what I have and tried commented out:
PHP Code:
function rand_uni($high){
$num_to_convert=rand(1,$high);
if($num_to_convert<10){
$rand_num_out="000" . $num_to_convert ;
}else if($num_to_convert<100){
$rand_num_out="00" . $num_to_convert ;
}else if($num_to_convert<1000){
$rand_num_out="0" . $num_to_convert ;
}else{
$rand_num_out= $num_to_convert;
}
echo $rand_num_out;
//global $rand_num_out;
}
//which is called in //
function obj(){
$obj_height = "100";
$obj_width = "150";
$obj_directory = "_img/_objects/";
if (glob("$obj_directory*.gif") != false)
{
$obj_filecount = count(glob("$obj_directory*.gif"));
//rand_uni($obj_filecount);
//global $rand_num_out;
//How I am Calling it now, wish I could just call the variable//
echo"<img src=\"" . $obj_directory;
rand_uni($obj_filecount);
echo ".gif\">";
}else{echo "no objects found :(";}
}
Bookmarks