Page 1 of 1

list direcotry problem using is_file and is_dir

Posted: Sat Oct 26, 2002 7:19 pm
by kendall
"Hello,

i am trying to list the contents of a direcotry based on whether it is a file or dir but i am having a problem and i cna tidentitfy it

CODE_--------

if ($AUTH !== ("level1" || "admin"))
{
while(list($k,$filename)=each($DIRFILES))
{
if(is_file($filename)){
echo "<a href=index.php?filename=".$filename."&download=true>".$filename."</a><br>";

}
}
}
-------------
the thing is based on the $AUTH variable if it didnt match i would print out the files and not the direcotry

but i dont get anything

if i were to remove the (is_file()) i would get the listing of everything

what seems to be the problem here cause i dont get it

Kendall

Posted: Sat Oct 26, 2002 8:56 pm
by volka
do you receive $DIRFILES by readdir? Do you opendir('.')?
If not you have to prepend the directory's name since readdir provides only the name not the path of a file.

is_file is_dir() problem

Posted: Mon Oct 28, 2002 7:17 am
by kendall
Yes everything is being read by the readdir function

No i dont want to list the full path just the file

but the problem is

it lists the files and directories

and i don't want it to do that just list the files

see if i took out the is_file() it works fine

but if i use is_file() why does it list directories?

Kendall

Posted: Mon Oct 28, 2002 7:28 am
by volka
plz post (parts of) the script

Posted: Mon Oct 28, 2002 8:13 am
by ssand
is it because you are using $filename. which everything has a filename.

when I use readdir I usually refer to the $file

Code: Select all

if (is_file($file))
Steve

Posted: Mon Oct 28, 2002 9:49 am
by Wayne
try ...

Code: Select all

if(is_file($path.$filename))&#123; 
echo "<a href="index.php?filename=".$filename."&download=true">".$filename."</a><br>"; 

&#125;
$path being the the variable containing the path to the directory you are listing.

you made need to put a slash between $path and $filename depending on whether or not it is already on the end of the $path variable.

Posted: Tue Oct 29, 2002 1:57 pm
by kendall
HEY

the ($path.$file) thing worked

but this now brings me to a more difficult problem

if am going deeper into directories and sub directories how do i get the paths then?

what is the exact use of realpath()?

im trying to get the path info with out having to reveal the absolute paths

any advice

Kendall

Posted: Wed Oct 30, 2002 10:13 am
by Wayne
but no one can see the full path unless they are reading the script, then Im pretty sure there gonna have a good idea what the path is anyway???