I've been trying to write a bit of code to pic a random file to display as part of a page.
Basically it would work like picking a random image file, BUT I also want to display a bit of text as to what the image shows. So I've got html files with tables in doing an '<img src' to the images and the descriptions written in the cell next to them.
With trying to pull up a html file though I don't seem to be getting any output (no error messages either).
This is the code I'm using:
<?php
//directory here (relative to script)
$path = 'data/';
$i = 0;
$dataDir = opendir ($path);
while ( $file = readdir( $dataDir ) )
{
//checks that file is html
$file_type = strrchr( $file, "." );
$is_html = eregi( "html",$file_type );
if ( $file != '.' && $file != '..' && $is_html )
{ $data[$i++] = $file; }
}
closedir ($dataDir);
srand( (double) microtime()*1000000 );
$file_name = $path . '/' . $data[rand( 0,sizeof( $data ) -1 )];
//ends script if no files found
if ( $i == 0 )
die();
print ( "<?php error_reporting(7) require(\"./$file_name\"); ?>" );
?>
Have I made some blatantly obvious and simple mistake?