Page 1 of 1
Folders
Posted: Wed Sep 15, 2010 3:13 am
by SpiritWebb
Is there a way in PHP or HTML, to show a listing of files as links in specified folder, that updates when you place a new file in that folder?
Say for example, someone uploads a music file to say /music/uploads/
Now, they go to see uploaded music, and it displays all and any recently uploaded music? If so, how can this be achieved? Thanks in advance...
Re: Folders
Posted: Wed Sep 15, 2010 3:47 am
by SpiritWebb
Nevermind, I have figured it out. For those that ever need to know how to do this:
Code: Select all
<?php
$dir=opendir("foldername"); //folder you wish to display
$files=array();
while (($file=readdir($dir)) !== false)
{
if ($file != "." and $file != ".." and $file != "yourfilename.php") //yourfilename is the file you choose to save this .php file as
{
array_push($files, $file);
}
}
closedir($dir);
sort($files);
foreach ($files as $file)
print "<A href='foldername/$file'>$file</a><br> //folder you wish to display, if its the same folder, just remove foldername/
";
?>
Re: Folders
Posted: Wed Sep 15, 2010 4:08 am
by Jackolantern
Nice

While printing the directory contents may have limited application on the public internet, this can be very useful for other algorithms, such as creating a video upload site, or other situations where you need structured handling of uploaded files. Thanks!
Re: Folders
Posted: Wed Sep 15, 2010 5:43 am
by SpiritWebb
Never thought of it that way. I am using it for the work website I am building. When an employee turns in their paperwork (uploaded as .pdf) it will go to said folder, and us team leads can then go back in and review them. I set it up this way for ways of saving paper, going green!
