Forum Moderators: coopster

Message Too Old, No Replies

2 exactly the same dir content retrieval scripts, only lists contents

         

dmmh

2:09 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



I do know how this error is caused, since I am on a shared host for now, PHP's safe mode is enabled and the failing script apperently is not the owner of the files/ dirs

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?

Little_G

2:33 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



Hi,

This worked for me:


<?php
$path = "images/";
$img_arr = array();
if($handle = opendir($path)) {
while (false!== ($file = readdir($handle))){
if([b]is_file($path . $file)[/b]){
if($file!= "." && $file!= ".."){
$img_arr[] = $file;
}
}
}
closedir($handle);
}
asort($img_arr);
reset($img_arr);
?>

Andrew

dmmh

3:00 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



had to modify that a bit to this:

$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 :)