Results 1 to 5 of 5
  1. #1

    listing files in a directory

    hi everyone,

    I am not sure how I can explain this but let's give a try

    I install pictures to a directory and want to make a list of them and the visitors will be able to click and see the image.

    You all know the ordinary listing page that appears if you don't install an index file to the directory. What I want to do is to have a page that'll work the same way with it, but have a design so that it'll look like the rest of the website.

    How can I do such a thing?
    Everything you need to know about web hosting business..
    Realible and low-cost web hosting..
    30 Day Money Back Guarantee & Paypal Accepted

  2. #2
    Join Date
    Jun 2004
    Bay Area -USA
    It's not too hard.

    i havnt tested this so you may need to tweak it. (im modding a script I found online)

    PHP Code:
    $dirpath "/path/to/your/directory";
    $dh opendir($dirpath);
    "<table width='500px'>";
           while (
    false !== ($file readdir($dh))) {
    //Don't list subdirectories
    if (!is_dir("$dirpath/$file")) {
    //Truncate the file extension and capitalize the first letter
    echo "<tr><td><a href='$file'>" htmlspecialchars(ucfirst(preg_replace('/\..*$/'''$file))) . "</a></td></tr>";
    This will list all the files in the directory... tell me if it works.
    <<< Please see Forum Guidelines for signature setup. >>>

  3. #3
    Join Date
    Oct 2004
    It wont be hard to write a small file to look through the directory and list the files it finds in there. A very few lines of code could do this, but it would not be alphabeticalized and would only include the filename, no extra details about the file.

    Further programming could accomplish a lot more. Let me know if you only want the simple script and I'll bash one together for you quickly.

  4. #4
    Here's an equivalent perl version:

    use strict;
    use warnings;
    use CGI::Pretty qw/:standard/;
    print header, start_html('Images');
    opendir( DIR, 'images/' ) || die "Could not open the current directory. $!";
    my @rows = ();
    foreach ( sort readdir(DIR) ) {
        next if /^\.+/;
        next if -d;
        my $file = $_;
        $_ = ucfirst;
        push( @rows, td( a( { href => $file }, $_ ) ) );
    print table( Tr( \@rows ) ), end_html;

  5. #5
    Join Date
    Mar 2004
    Testing 1.. Testing 1..2.. Testing 1..2..3...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts