Forum Moderators: coopster
what is strange is that I have the exact same part of this script in place to list all images related to a movie and this works. It counts 8 images if there are 8 and skips directories and the array containing the images is passed to a image resize/ display function, which works fine. The other one is a few directories down, but in the same directory seen from the webroot.
This one SHOULD retrieve the same array, but returns 0 files
this is it:
$f = 0;
$nr_images = 0;
$img_arr = array();
if (@$handle = opendir($path)) {
while (false!== ($file = readdir($handle))) {
if( $file!= "." && $file!= ".." && $file[0]!= "." ) {
if(is_file($file)){
$nr_images++;
$img_arr[$f++] = $file;
}
}
}
closedir($handle);
}
asort( $img_arr ); reset( $img_arr );
I know it has to do with is_file(), is_file() will return FALSE if the running script isnt the owner of the file, the same goes for is_dir()
how then is it one works and another doesnt?
$f = 0;
$nr_images = 0;
$img_arr = array();
if ($handle = opendir($path)) {
while (false!== ($file = readdir($handle))) {
if( $file!= "." && $file!= ".." && $file[0]!= "." ) {
$file = $path.'/'.$file;
if(is_file($file)) {
$file = basename($file);
$nr_images++;
$img_arr[$f++] = $file;
}
};
};
closedir($handle);
}
asort( $img_arr ); reset( $img_arr );
but now its working, thanks for pointing the $path bit out to me :)