Hallo ik heb een eenvoudig script geschreven dat een random set images tevoorschijn tovert, maar op sommige servers krijg ik de volgende error.
Hij voert het script wel gewoon goed uit, maar ik snap die error niet helemaal.
Het pad klopt wel gewoon. Hopelijk weet iemand van jullie raad. Alvast bedankt voor de moeite!
ERRORMELDING
Warning: 1 is not a valid Directory resource in header.php on line 29
(regel 29 is while($tmpFile = readdir($handle))
HET SCRIPT
<?
$handle = opendir( "/home/sites/site111/web/demo/images/random" );
$imgArray = array( );
while( $file = readdir( $handle ) ) {
if( $file != "." && $file != ".." ) {
array_push( $imgArray, $file );
}
}
closedir( $handle );
mt_srand( (double)microtime( ) * 1000000 );
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>[img]\"images/welkom.gif\"[/img]</a></td>";
$images = array();
$theList = array();
while($tmpFile = readdir($handle))
if($tmpFile != '.' && $tmpFile != '..')
$theList[] = $tmpFile;
srand ((float) microtime() * 10000000);
$theRandomList = array_flip($theList);
foreach($theList as $theImage)
; // do something with '$theImage'
$x = 0;
while ($x <= 7) {
$randval = mt_rand( 0, sizeof( $imgArray ) - 1 );
if (!in_array($randval,$images)) {
if (substr($imgArray[$randval],-4) == ".jpg") {
print( "<td>[img]\"images/random/"[/img]</td>" );
$images[] = $randval;
$x = $x + 1;
}
}
}
echo "</tr></table>";
?>
Hij voert het script wel gewoon goed uit, maar ik snap die error niet helemaal.
Het pad klopt wel gewoon. Hopelijk weet iemand van jullie raad. Alvast bedankt voor de moeite!
ERRORMELDING
Warning: 1 is not a valid Directory resource in header.php on line 29
(regel 29 is while($tmpFile = readdir($handle))
HET SCRIPT
<?
$handle = opendir( "/home/sites/site111/web/demo/images/random" );
$imgArray = array( );
while( $file = readdir( $handle ) ) {
if( $file != "." && $file != ".." ) {
array_push( $imgArray, $file );
}
}
closedir( $handle );
mt_srand( (double)microtime( ) * 1000000 );
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>[img]\"images/welkom.gif\"[/img]</a></td>";
$images = array();
$theList = array();
while($tmpFile = readdir($handle))
if($tmpFile != '.' && $tmpFile != '..')
$theList[] = $tmpFile;
srand ((float) microtime() * 10000000);
$theRandomList = array_flip($theList);
foreach($theList as $theImage)
; // do something with '$theImage'
$x = 0;
while ($x <= 7) {
$randval = mt_rand( 0, sizeof( $imgArray ) - 1 );
if (!in_array($randval,$images)) {
if (substr($imgArray[$randval],-4) == ".jpg") {
print( "<td>[img]\"images/random/"[/img]</td>" );
$images[] = $randval;
$x = $x + 1;
}
}
}
echo "</tr></table>";
?>