vendredi 10 avril 2015

Random image of day (PHP)

Hello to all you wonderful coders out there. I'm a total noob when it comes to coding so, here it goes.


I'm trying to add a simple random image of the day script. It doesn't point to the right file location though. Here is the code:





<?php
$i=0;
$path="images";
$ext = "jpg";
$extra= "alt=\"Random Image\" float=\"left\"";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (substr($file,strlen($file)-3,3)==$ext)
{ $imgs[$i++]=$file;
}
}
closedir($handle);
$today=getdate();

srand($today['mday']+$today['month']+$today['year']);

$r=rand(0,$i-1);

echo("<img src=images/\"$imgs[$r]\" $extra>");

}

?>



The image source when I right click and check properties is adding %22 before and after the file. EX: mobile/images/%22image.jpg%22


Therefore, the image isn't showing because of it I presume.


Thanks for your time.


Aucun commentaire:

Enregistrer un commentaire