Rightio, I need to count the number of files in a directory then assign that number to a variable in my website. Here is what I have thus far.
PHP Script to count files
And here is my javascript which is inside my html pagePHP Code:$directory = "../comics/";
if (glob($directory . "*.png") != false)
{
$filecount = count(glob($directory . "*.png"));
echo $filecount;
}
else
{
echo 0;
}
Now, my problem is this, it wont get the file count. If I set numofImages to an actual number the entire thing works perfectly fine. But for some reason it doesn't seem to get the file count. Any tips?Code:<script type="text/javascript"> var numofImages = "<?=$filecount?>"; var random_img = new Array(); for(var i=0;i<numofImages-1;i++) { random_img[i] = '<a href="comics/'+i+'.png"><img src="comics/'+i+'.png"; width="260" height="320" border="0" alt=""></a>'; } var random_number = Math.floor((Math.random()*random_img.length)); random_img[random_number]; document.write(random_img[random_number]); </script>
Cheers.


Reply With Quote

Bookmarks