Forum Moderators: coopster
<?php
function rndImage(){
$folder = "images"; /// Change this to your img folder
$imgFiles = Array();
$dirHandler = opendir($folder) or die("cannot opendir");
while($myImages = readdir($dirHandler)){
if($myImages == "." ¦¦ $myImages == ".."){continue;}
array_push($imgFiles,$myImages);
}
$imgNo = rand(0, count($imgFiles));
$imgName = $folder."/".$imgFiles[$imgNo];
echo $imgName;
}
?>
when you wan to put random img:
<IMG SRC="<?php rndImage()?>">
What I want to do is:
Lets say I have a blog looking site, and on the right side on the top there is this box.
I would like to show the random picture there, and here comes the part where I need help.
Is that anyway to make sure that it gets"rezized" tempoary when showed in that box?
Lets say max: 145px times 177px and THEN when you click on it, it will lead you to the full image...
HELP?
I made a test by creating a new file called: testing.php
and I wrote this:
<?php
function rndImage(){
$folder = "images"; /// Change this to your img folder
$imgFiles = Array();
$dirHandler = opendir($folder) or die("cannot opendir");
while($myImages = readdir($dirHandler)){
if($myImages == "." ¦¦ $myImages == ".."){continue;}
array_push($imgFiles,$myImages);
}
$imgNo = rand(0, count($imgFiles));
$imgName = $folder."/".$imgFiles[$imgNo];
echo $imgName;
}<IMG SRC='<?php rndImage()?>' width=145 target=_blank>
?>
it says error in line 7?
what did I do wrong?
So just the problem is to trap 'width' and 'height' of full images ( different images are of different dimensions ). so can either store that in db or if you can get it from filesystem image file ( using gd library perhaps? ) I can't try code for you :)
This is how I have written it, and it still says:
Parse error: parse error, unexpected T_STRING in /home2/clickspa/public_html/admin.php on line 7