Thread: php directory listing
-
September 8th, 2004, 05:13 PM #1
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.
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?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>
if anyone has any idea let me know.
Thx,
vhockey86
-
September 8th, 2004, 05:16 PM #2
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
-
September 8th, 2004, 05:23 PM #3
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?
-
September 8th, 2004, 08:12 PM #4
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
-
Serv-U through a router/firewall
By MaximumAsh in forum Networking and InternetReplies: 5Last Post: June 24th, 2004, 10:47 AM -
HELP WITH MY SITE
By yukkerz in forum Webmastering and ProgrammingReplies: 14Last Post: November 13th, 2003, 02:54 PM -
Directory Browsing
By BlueIce in forum Applications and Operating SystemsReplies: 1Last Post: October 19th, 2003, 04:58 PM -
debian boot floppies?
By e980238 in forum Applications and Operating SystemsReplies: 19Last Post: September 11th, 2002, 01:43 PM



LinkBack URL
About LinkBacks



Reply With Quote


14 year old, Eruption, Van Halen...need I say more?? Van Halen - Eruption Guitar Cover - YouTube
Is It Just Me? v233893843