list direcotry problem using is_file and is_dir

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

list direcotry problem using is_file and is_dir

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

is_file is_dir() problem

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

plz post (parts of) the script
ssand
Forum Commoner
Posts: 72
Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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???
Post Reply