+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Perfetc Member VHockey86's Avatar
    Join Date
    Jan 2003
    Location
    Maryland Suburbia
    Posts
    4,334

    php directory listing

     
    First I'd like to mentioned that I know very little actual php... I've just been working/editing script that I've found online.

    With that said, this is what I've been doing/attempting to do.

    I wanted a simply way that I could upload/download files from my website without needing to bother with an FTP/client and such on other machines around campus (like the CS labs for example). Anyways, I found a php form upload script online which seems to work just fine. Now however, I wanted a way to be able to see all the files in a particular directory from the webbrowser.

    http://www.andrewpangborn.com/upload/files/
    Thats what I've managed to do so far.
    Code:
    <table border="1" align="center">
    <tr>
    	<td><B>File Name:</B></td>
    	<td><B>Link to File:</B></td>
    	<td><B>File Size:</B></td>
    </tr>
    <?php
    
    $directory = opendir('.');
    while ($file = readdir($directory)) {
     if ($file != '.' && $file != '..') {
      $files[] = $file;
      $filesizes[] =  filesize($file);
     }
    }
    closedir($directory);
    
    while (list($key,$filename) = each($files)) {
    list($key2,$filesizes2) = each($filesizes);
    echo "<tr>
    		<td>$filename</td>
    		<td><a href=$filename> $filename </a></td>
    		<td>$filesizes2";
    		echo " Bytes</td>
    	</tr>";
    }
    ?>
    </table>
    It works but it seems to be rather randomly sorted. I was wondering how I would go about having the list sorted by filename. Note that the way I managed to do it above, the filesize and filenames are in seperate arrays... so I dont think I could simply use some sort of sorting after the fact. Perhaps there is a way to pass an attribute with the "readdir()" command so that it outputs it alphabetically?

    if anyone has any idea let me know.

    Thx,
    vhockey86

  2. #2
    Senior Member kantlivelong's Avatar
    Join Date
    Jul 2003
    Location
    NY
    Posts
    775
    make each dir into an array.. then use the array sorting function.. then do a foreach or some other type of way to output... http://php.net is all you need for a refrence..

    Edit: see you have arrays for filesize.. just do this..

    $filename= "php.txt";
    ArrayName[$filename][size]=SIZE
    ArrayName[$filename][type]=TYPE

    hope that helps more..
    RackByte.com - Web Hosting / Reseller Hosting / VPS / Dedicated Servers / Domain Registration

  3. #3
    Perfetc Member VHockey86's Avatar
    Join Date
    Jan 2003
    Location
    Maryland Suburbia
    Posts
    4,334
    I dont really follow you....
    Does adding additional []s to an array add another property to the array? Suchthat it has multiple properties under a single varialbe?

  4. #4
    Senior Member kantlivelong's Avatar
    Join Date
    Jul 2003
    Location
    NY
    Posts
    775
    in some sort of twisted way they do.. arrays can be within arrays...
    RackByte.com - Web Hosting / Reseller Hosting / VPS / Dedicated Servers / Domain Registration

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Serv-U through a router/firewall
    By MaximumAsh in forum Networking and Internet
    Replies: 5
    Last Post: June 24th, 2004, 10:47 AM
  2. HELP WITH MY SITE
    By yukkerz in forum Webmastering and Programming
    Replies: 14
    Last Post: November 13th, 2003, 02:54 PM
  3. Directory Browsing
    By BlueIce in forum Applications and Operating Systems
    Replies: 1
    Last Post: October 19th, 2003, 04:58 PM
  4. debian boot floppies?
    By e980238 in forum Applications and Operating Systems
    Replies: 19
    Last Post: September 11th, 2002, 01:43 PM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews