HELP! I need to list files but not folders!

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
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

HELP! I need to list files but not folders!

Post by gotDNS »

Hey, I have a page that lists all the stuff in a DIR, but that includes folders. Anybody know a way for me to have it show only files?

Thanks?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

there is similar post around here (don't know exactly where).
replace the print/echo by

Code: Select all

<?php
if(is_file($name)) 
        print($name);
?>
as mentioned in the user contributed notes for is_file you should call clearstatcache to free the memory used for caching the file stats when it's not used anymore.ost around here (don't know exactly where).
replace the print/echo by

Code: Select all

<?php
if(is_file($name)) 
        print($name);
?>
as mentioned in the user contributed notes for is_file you should call clost around here (don't know exactly where).
replace the print/echo by

Code: Select all

<?php
if(is_file($name)) 
        print($name);
?>
as mentioned in the user contributed notes for is_file you should call [url=http://www.php.net/manual/enost around here (don't know exactly where).
replace the print/echo by

Code: Select all

&lt;?php
if(is_file($name)) 
        print($name);
?&gt;
as mentioned in the user contributed notes for is_file you should call clearstatcache to freeost around here (don't know exactly where).
replace the print/echo by

Code: Select all

<?php
if(is_file($name)) 
        print($name);
?>
as mentioned in the user contributed notes for is_file you should call clearstatcache[ost around here (don't know exactly where).
replace the print/echo by

Code: Select all

&lt;?php
if(is_file($name)) 
        print($name);
?&gt;
as mentioned in the user contributed notes for is_file you should call clearstatcache to free the memory used for cctly where).
replace the print/echo by

Code: Select all

<?php
if(is_file($name)) 
        print($name);
?>
as mentioned in the user contributed notes for is_file you should call [url=http://www.php.net/man<?php
if(is_file($name))
print($name);
?>
as mentioned in the user contributed notes for is_file you should call clearstatcache to free the memory used for caching the file stats when it's not used anymore.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

<?
$root = "/";
 if ($handle = opendir($root)) &#123;
   while($file = readdir($handle)) &#123;
     if ($file == &#1111;a-zA-Z0-p_-]*.php) &#123;
 $create = filemtime($file);
$create_2 = date("m/d/Y h:i:s", $create);
      echo "what you want to echo";
     &#125;
   &#125;
   closedir($handle);
 &#125; 

?>
just change the extension in the line

if ($file == [a-zA-Z0-p_-]*.php) {

to whaetver you want, and you can also do like

if ($file == [a-zA-Z0-p_-]*.php | $file == [a-zA-Z0-p_-]*.html) {

to include both html or php files...
and then you just echo like a link to the file, $file being the filename...
or do whatever you want,

someone correct my errors if there are any
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

now I can say: This was not the question ;)
He already has a script that shows the content of a directory and only wants to filter out the directories.
But anyway filtering the filename extensions may be good for security reasons
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

yes, but only viewing a couple filenames, won't view the directories, at least that was what i was trying to do :roll:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

neither would I allow users to view the whole contents of a directory.
They shall create their own local directories if they'd like to view all of it's stuff :D
Post Reply