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...
Folders
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Folders
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/
";
?>
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Folders
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!
The indelible lord of tl;dr
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Folders
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! 

