Page 1 of 1

HELP! I need to list files but not folders!

Posted: Tue May 21, 2002 3:28 pm
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?

Posted: Tue May 21, 2002 5:43 pm
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.

Posted: Tue May 21, 2002 6:30 pm
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

Posted: Tue May 21, 2002 6:58 pm
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

Posted: Tue May 21, 2002 7:11 pm
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:

Posted: Tue May 21, 2002 7:57 pm
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