FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to: Display the files in a directory on a page?





xxmassive
how to: Display the files in a directory on a page?

I want to make this http://iourt.com/maps/q3ut4/
but than by using a script.
sonam
I don't think you need script to display files in some directory. Just don't put in pages with names index, default, home (maybe some other - independent of server specification). If server didn't find pages with this names then will display files.

Sonam
rickylau
Yeah sonam's one is the easiest way, and exactly how your example works. Just FYI, if you really need to list file using script, why don't you take a look at PHP's reference? There's an example which suits your need.
jmraker
You can use the glob function
http://us3.php.net/glob
Code:
<?php
foreach(glob('*.html') as $file){
    echo $file . '<br />';
}
?>


or the opendir/readdir/closedir functions
http://us3.php.net/manual/en/function.opendir.php
Code:

$dir = '.';
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo $file . '<br />';
        }
        closedir($dh);
    }
}
rvec
http://httpd.apache.org/docs/1.3/mod/mod_autoindex.html
Make a .htaccess file with the content:
Code:
Options +Indexes

And the job should be done for you by apache like sonam said.
MM357
jmraker wrote:
You can use the glob function
http://us3.php.net/glob
Code:
<?php
foreach(glob('*.html') as $file){
    echo $file . '<br />';
}
?>


or the opendir/readdir/closedir functions
http://us3.php.net/manual/en/function.opendir.php
Code:

$dir = '.';
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo $file . '<br />';
        }
        closedir($dh);
    }
}


Both are working great for me, but the first one didn't output the two directories "." and ".." (this directory and the parent directory) unlike the second one .. so reading a bit in the ref page u provided I came up with a small addition to make the result same :-

Code:

<?php
foreach(glob('{..,.,*}',GLOB_BRACE) as $file){
    echo $file . '<br />';
}
?>


moreover, php provided some interesting functions to handle files .. http://us3.php.net/manual/en/ref.filesystem.php

so u can add some info about the file like :-

Code:

<?php
foreach(glob('{..,.,*}',GLOB_BRACE) as $file){
    echo '<a class="'.filetype($file).'" href="'.$file.'">'.$file . '</a><br />';
    echo ((!is_dir($file)) ? '--size:'.filesize($file).'<br />' : '');
    echo '--date:'.date ("F d Y H:i:s.", filemtime($file)).'<br /><br />';
}
?>
Related topics
foobar or winamp?
password protecting a directory
Scalable (in size) Forums - Is there such a thing?
Virus leftover :)
Opera 9.0 Technology Preview 2
Layout gap problems with Javascript/PHP Combo
Anonymous logins to FTP
General .htaccess tutorial.
83% bandwidth used, tho low visitor rate
[Solved, 9 hr] HTTPD in server2 DOWN
Firefox/LAN problem
.html vs .php
Reinstall windows easily?
Where do I post this: Directory Top 11 issue
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.