Servers can be configured to show the contents of a directory that doesn’t have an index file to render. The result is usually less than visually spectacular:


We can take control of this ourselves by replicating this functionality with PHP.
- Make an index file (
.index.php
, starting with the dot, really) which reads the files in the directory and outputs them into a table - Make an
.htaccess
file that serves that file as the index - Have the index file load in CSS and other resources that are also prefixed with a dot (hidden)
The following PHP reads the directory of files and displays a styled table of their name, file type, and file size. It also applies a class name in which to apply icons for the different major file types (see CSS).
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Directory Contents</title>
<link rel="stylesheet" href=".style.css">
<script src=".sorttable.js"></script>
</head>
<body>
<div id="container">
<h1>Directory Contents</h1>
<table class="sortable">
<thead>
<tr>
<th>Filename</th>
<th>Type</th>
<th>Size <small>(bytes)</small></th>
<th>Date Modified</th>
</tr>
</thead>
<tbody>
<?php
// Opens directory
$myDirectory=opendir(".");
// Gets each entry
while($entryName=readdir($myDirectory)) {
$dirArray[]=$entryName;
}
// Finds extensions of files
function findexts ($filename) {
$filename=strtolower($filename);
$exts=split("[/\\.]", $filename);
$n=count($exts)-1;
$exts=$exts[$n];
return $exts;
}
// Closes directory
closedir($myDirectory);
// Counts elements in array
$indexCount=count($dirArray);
// Sorts files
sort($dirArray);
// Loops through the array of files
for($index=0; $index < $indexCount; $index++) {
// Allows ./?hidden to show hidden files
if($_SERVER['QUERY_STRING']=="hidden")
{$hide="";
$ahref="./";
$atext="Hide";}
else
{$hide=".";
$ahref="./?hidden";
$atext="Show";}
if(substr("$dirArray[$index]", 0, 1) != $hide) {
// Gets File Names
$name=$dirArray[$index];
$namehref=$dirArray[$index];
// Gets Extensions
$extn=findexts($dirArray[$index]);
// Gets file size
$size=number_format(filesize($dirArray[$index]));
// Gets Date Modified Data
$modtime=date("M j Y g:i A", filemtime($dirArray[$index]));
$timekey=date("YmdHis", filemtime($dirArray[$index]));
// Prettifies File Types, add more to suit your needs.
switch ($extn){
case "png": $extn="PNG Image"; break;
case "jpg": $extn="JPEG Image"; break;
case "svg": $extn="SVG Image"; break;
case "gif": $extn="GIF Image"; break;
case "ico": $extn="Windows Icon"; break;
case "txt": $extn="Text File"; break;
case "log": $extn="Log File"; break;
case "htm": $extn="HTML File"; break;
case "php": $extn="PHP Script"; break;
case "js": $extn="Javascript"; break;
case "css": $extn="Stylesheet"; break;
case "pdf": $extn="PDF Document"; break;
case "zip": $extn="ZIP Archive"; break;
case "bak": $extn="Backup File"; break;
default: $extn=strtoupper($extn)." File"; break;
}
// Separates directories
if(is_dir($dirArray[$index])) {
$extn="<Directory>";
$size="<Directory>";
$class="dir";
} else {
$class="file";
}
// Cleans up . and .. directories
if($name=="."){$name=". (Current Directory)"; $extn="<System Dir>";}
if($name==".."){$name=".. (Parent Directory)"; $extn="<System Dir>";}
// Print 'em
print("
<tr class='$class'>
<td><a href='./$namehref'>$name</a></td>
<td><a href='./$namehref'>$extn</a></td>
<td><a href='./$namehref'>$size</a></td>
<td sorttable_customkey='$timekey'><a href='./$namehref'>$modtime</a></td>
</tr>");
}
}
?>
</tbody>
</table>
<h2><?php print("<a href='$ahref'>$atext hidden files</a>"); ?></h2>
</div>
</body>
</html>
The resources loaded in that index file are the top-in table sorter script sortable.js and a .style.css file. (Remember, prefacing the files with a dot makes the invisible in most operating systems, and also won’t show up in your directory of files (good)). Here’s that CSS:
* {
padding:0;
margin:0;
}
body {
color: #333;
font: 14px Sans-Serif;
padding: 50px;
background: #eee;
}
h1 {
text-align: center;
padding: 20px 0 12px 0;
margin: 0;
}
h2 {
font-size: 16px;
text-align: center;
padding: 0 0 12px 0;
}
#container {
box-shadow: 0 5px 10px -5px rgba(0,0,0,0.5);
position: relative;
background: white;
}
table {
background-color: #F3F3F3;
border-collapse: collapse;
width: 100%;
margin: 15px 0;
}
th {
background-color: #FE4902;
color: #FFF;
cursor: pointer;
padding: 5px 10px;
}
th small {
font-size: 9px;
}
td, th {
text-align: left;
}
a {
text-decoration: none;
}
td a {
color: #663300;
display: block;
padding: 5px 10px;
}
th a {
padding-left: 0
}
td:first-of-type a {
background: url(./.images/file.png) no-repeat 10px 50%;
padding-left: 35px;
}
th:first-of-type {
padding-left: 35px;
}
td:not(:first-of-type) a {
background-image: none !important;
}
tr:nth-of-type(odd) {
background-color: #E6E6E6;
}
tr:hover td {
background-color:#CACACA;
}
tr:hover td a {
color: #000;
}
/* icons for file types (icons by famfamfam) */
/* images */
table tr td:first-of-type a[href$=".jpg"],
table tr td:first-of-type a[href$=".png"],
table tr td:first-of-type a[href$=".gif"],
table tr td:first-of-type a[href$=".svg"],
table tr td:first-of-type a[href$=".jpeg"] {
background-image: url(./.images/image.png);
}
/* zips */
table tr td:first-of-type a[href$=".zip"] {
background-image: url(./.images/zip.png);
}
/* css */
table tr td:first-of-type a[href$=".css"] {
background-image: url(./.images/css.png);
}
/* docs */
table tr td:first-of-type a[href$=".doc"],
table tr td:first-of-type a[href$=".docx"],
table tr td:first-of-type a[href$=".ppt"],
table tr td:first-of-type a[href$=".pptx"],
table tr td:first-of-type a[href$=".pps"],
table tr td:first-of-type a[href$=".ppsx"],
table tr td:first-of-type a[href$=".xls"],
table tr td:first-of-type a[href$=".xlsx"] {
background-image: url(./.images/office.png)
}
/* videos */
table tr td:first-of-type a[href$=".avi"],
table tr td:first-of-type a[href$=".wmv"],
table tr td:first-of-type a[href$=".mp4"],
table tr td:first-of-type a[href$=".mov"],
table tr td:first-of-type a[href$=".m4a"] {
background-image: url(./.images/video.png);
}
/* audio */
table tr td:first-of-type a[href$=".mp3"],
table tr td:first-of-type a[href$=".ogg"],
table tr td:first-of-type a[href$=".aac"],
table tr td:first-of-type a[href$=".wma"] {
background-image: url(./.images/audio.png);
}
/* web pages */
table tr td:first-of-type a[href$=".html"],
table tr td:first-of-type a[href$=".htm"],
table tr td:first-of-type a[href$=".xml"] {
background-image: url(./.images/xml.png);
}
table tr td:first-of-type a[href$=".php"] {
background-image: url(./.images/php.png);
}
table tr td:first-of-type a[href$=".js"] {
background-image: url(./.images/script.png);
}
/* directories */
table tr.dir td:first-of-type a {
background-image: url(./.images/folder.png);
}
REMEMBER: The .zip file might appear to be empty, but it’s not. The files are all prefaced with a dot. View them in a file editor which shows you “hidden” files.
Special thanks to Cliff White.
Update November 2012: The demo and downloadable files have been updated to (1) show more human readable file sizes (2) have error pages
You need to change line 136 to this to avoid a Parse error.
a href='$dirArray[$index]'
After that this works perfect! Thanks for sharing!
//T
There were \” marks in there to make sure that wasn’t a problem but for whatever reason weren’t showing up in the displayed code. I just made them single ticks to avoid problems, thanks!
It worked for me when i renamed .index.php to index.php removing the dot. Not sure why my server didint pick up what to do from the htaccess file
@ppahppp You need to enable .htaccess functionality in your apache server.
Make AllowOverride None to AllowOverride All just like shown below and restart apache.
AllowOverride All
Dear sir,
Styled Display Directory is cool but i want to show different directory file path how can do that in e drive there is a folder namely upload i want to set that whatever content it have that should be directly shown
great! ty
Im using IIS will it work for it?
@Toji K Dominic also if it’s a Windows IIS server you need to edit your Web.Config file:
<system.webServer>
</system.webServer>
how to show single director/folder like “Videos”
Icon function not working with pdf. favicon before filename are not appearing for pdf file. Which line of code should I edit or add to make it work?
Very nice script, thanks for sharing!
nice script. I’m sure I can find something to use this for :)
Looks really cool – I’ll definitely be using this for something or other.
sweet. and so simple. thanks!
Nice. Thanks.
line 141:
print(number_format((filesize($dirArray[$index])), 0, ”, ‘,’));
Nice!
One thing though: where can I find the little icons on the left of the file/folder please?
Here are the icons I used, they’re great for everything!
http://www.famfamfam.com/lab/icons/
The image for audio.png is incorrectly named sound.png – or the image sound.png is incorrectly called out as audio.png in the .style.css script! Also, I added:
table tr td:first-of-type a[href$=”.wav”],
to the list of sound file types, and it worked on my .wav’s too 8)
Thanks for this. This is a great bit of code and very easy to add even for a php newb like me.
I’m getting an error from this line:
print(filesize($dirArray[$index]));
I think it’s line 141 in the original, but I am just using the php part as an include with my own CSS so it’s line 48 in mine. Here is the error:
Warning: filesize() [function.filesize]: stat failed for archives in /..(path to my website).org/includes/directory_contents.php on line 48
I believe the error is because it is printing out the parent directory folder (and its parent, too), which have no filesize. It works great, except for those two lines – and I can’t figure out why they even are being printed, since they are not files IN the directory… My folder structure is
/newsletters/archives/index.php
and the first row of the table displaying the files shows “archives,” with the error under the filesize column, and the last row of the table shows “newsletters” and another filesize error.I’m just learning PHP, but I think a line to set the condition if there is no suffix, don’t include it might be fairly easy… for someone who is more fluent in PHP, anyway :)
Anyone have any ideas? Thanks!
I’m trying to figure it out, but realized that setting a condition for not printing a file without a “.” in the string won’t work, because the “files” that are causing the errors don’t actually exist – it’s showing the parent and “grandparent” directories as if they were files IN the directory – /newsletters/archives/archives and /newsletters/archives/newsletters
I can’t figure out what is causing that, and since they don’t actually exist in the directory, my idea for setting a condition of not printing a string without a “.” in it won’t have any effect. And it hasn’t.
Here’s the page:
http://bristleconecnps.org/newsletters/archives/index.php
I got it to stop displaying the empty line at the top and the first error – the archives one, by changing the loop to this:
for($index=4; $index < $indexCount; $index++) {
starting at “1” instead of 0 got rid of the blank, and starting at “4” takes into consideration the two parent directories which aren’t being shown plus the weird error one, and starts on the first real file. There is still the error at the end (last row) of the table.
Okay, my head hurts, and I hope some of you wonderful PHP people and problem solvers have some better ideas!
Thanks.
I just fixed it:
for($index=4; $index < $indexCount-1; $index++) {
(added -1 to the index count so it wouldn’t show the last “file”)
This is obviously a workaround that is specific to that file structure – if the directory was at a different level it would need to start at a different place, which makes using this code as an include for any directory index file I want on my site not as simple, but hey, it works!
Sorry for all the multiple comment posts, but I hope it may be helpful and/or interesting to someone! :)
And if someone has a better idea that will fix it instead of hiding it, I would love to hear it.
Thanks!!
This will prevent the last file from being listed in the directory. Do you have any idea on how to prevent the index.php from showing?
Put this line in your .htaccess file:
Then rename the file to .index.php (with the leading dot). The php script script will then prevent the showing of hidden files. The result: your index.php will not show up in the listings.
Very cool. Thank you very much Chris. I know I’m late in the game here but I’m definitely gonna use your script.
OK… I’ve played with this and it works great. Really excited about this but I don’t know enough to start adding stuff to the code. But what about adding a download function to the directory? Each of the items would get their own download button. Just an idea in case someone would like to try it. Thanks again for the script!
Hey this is great code works so sweet!
But I need to open up a different dir to where the script is located how do i do that?
Cannot get this to work. It only displays the headers on my page… no file listings, and there are plenty of files in the directory.
Any thoughts?
Dear all :
You can choose a certain file only , for example if you want to display “.doc” only without any files maybe exist in that folder, so then you should REPLACE this code instead of gets each entry to be seems as follow:
// gets each entry
while($entryName = readdir($myDirectory)) {
if (strpos($entryName, ‘.doc’,1) ) {
$dirArray[] = $entryName;
}
}
Zeyad
Anyone know how to get it to NOT display certain given files such as the favicon or the index.php file?
Better still for me: how do i make display ONLY the folder names?
Useful script. Thanks.
David
Hi David,
I had a closer look at this script, very useful indeed… my suggestion for you are:
Define (just before the while-loop): $forbiddenExts = array(“php”, “ico”, “html”);
In the while-loop, do the same as in findexts():
And if you want to display only folders, then add another line of code just before the first if:
Altogether:
!is_file()… you don’t want to display files… in my script I don’t want to display folders… ;-)
@Benjamin – I’m stumped. I only want to display folders, so I used your additional script and get “Notice: Undefined offset: 1 in…” for every folder displayed (so, in my case, 5 Notices).
I think this is referring to the section of code that reads:
if(!in_array($exts[1],$forbiddenExts))
Suggestions?
great script, but i can’t figure out how i can change the folder.
every time i change the directory there will appear a mistake in that in in which sort($dirArray); located.
what i’m supposed to do?
just another method i have used before, which displays the contents of a folder, and gives a link and preview… if anybody wants the code, let me know. example is http://www.inktecbots.com/specials.php
Hello, I like the look of your example, can you please let me have the code
yes please i want this way
hi..
i m just learning to use php… this code is gr8…
i m getting the parse error… so what is the change in line 136?
thanx
hey, im getting this to work really well, but what if i wanted to display folders and files, but excluding the php and icon files? what would i need to change?
look at @Benjamin’s post above yours!
right…but in some instances i want it to display both files AND folder, but NOT the *.ico and *.php files
Life. Saver.
I have customized the script to create a simple with links from given folders. You don’t know how this helped me out, thanks a lot.
Thanks buddy! helped me a lot
if one chances the line $myDirectory line to:
$myDirectory = opendir(“c:\docs”);
The files in the docs directory are listed correctly, however, when one clicks on the link the link ties to load the file from the localhost directory.
Is there an easy way of linking to the the files in the c:\docs directory?
Thanks
Thanks for this piece of code. Cute one
Im learner for php. This code show some error. the extenson of this file is .php rite?
excatly wht my requirement is to dispaly the file in particular local folder in webpage…. so tht clicking on the links the file shuld get downloaded….. pls can anyone help me in doin this?. i need in html
Just as a heads up, split() is deprecated in php5.3 so you will want to modify like so:
$exts = explode("[/\\.]", $filename) ;
It worked for me. Thank you very much for share!
This is not working for me. I used it as it is in php 5 but i is not working at all. what should I modify?
I’m having an issue displaying the file size when I change the directory.
http://infasyssolutions.com/control.php
Above is what I’m trying to make work. If i leave it to the (“.”) everything works perfect, but when I change it to (“images”) everything but the file size works. Any ideas as to why?
Hai.. this code helps me alot..
but i need to listout folders in the directory and also if there is any documents in that folder that also should be listout..please help me
I found a fix the issue with changing the directory.
The problem was that changing the directory prevented the hyperlink to the file from working, along with preventing the PHP processor from accessing the file to read its size. Even though it still listed the files in the folder as intended.
Do the following:
————————————————————————–
*Replace the lines:
with the lines:
————————————————————————–
Also replace:
with
You may need to use if you version of PHP is 5.3 or later.
————————————————————————–
Replace:
with:
————————————————————————–
and replace:
with
Thank you so much, Jonathan! I’ve was stumped by the directory issues and your comments worked like magic!
We would like to thank you for the great script you have made. Specially the thing with transperent effeect. It’s one of the coolest thing on earth.
Is there any way to load a directory from an external domain?
Not without FTP access.
Great piece of work which no doubt will help many people.
I also found the reworking of the script to show the contents of a different folder/location to be very helpful as it overcomes the problems of showing certain file types which you may not otherwise wish to make viewable.
I did however find one small issue after the rework in as much as the icons for the file types weren’t displaying in the directory listing … and in my case, having put the icons in a folder called ‘img’ I simply had to change the following lines 60 through to 89 …
I’ll only give one example to save space :
71 /*docs*/
72 a[href$=”.doc”] {background: url(img/doc.gif) no-repeat left 50%;}
73 a[href$=”.txt”] {background: url(img/doc.gif) no-repeat left 50%;}
74 a[href$=”.rtf”] {background: url(img/doc.gif) no-repeat left 50%;}
I hope this helps … even just one person …
Anyway … MAGNIFICENT script … MANY THANKS ;-)
To get filesize of a file from another directory :
$dirname = "./YourFolderName" //Change "YourFolderName" to your folder's name
$filez = $dirArray[$index]; //Get the name of file
$path = $dir.'/'.$filen; //Path address of the file (included the directory path)
$size = filesize($path); //Get the size of a file
print("$size"); //print the size
I use PHP 5.2.10, it works fine .
HI, very nice script – thanks a lot.
I have created a page that shows the latest pdf on my web using google docs viewer.
Could the code be added to the script, so that a “view online” link is added to the file list?
The code I´m using is as follows:
” iframe src=”http://docs.google.com/gview?url=http://www.benitezjones.com/uploads/ultima.pdf&embedded=true” style=”width:718px; height:700px;” frameborder=”0″
Any ideas?
How to display the last modified date?
Add this line inside the while loop:
And then this wherever you want to output that time (still must be inside the loop):
How do you also create a css archive by adding thumbnail using first image and excerpt of a file.
Dear All;
thanks Jesus
if body can help that question
How to display the last modified date
————————————————–
Question to Help :
How to display results in limit for 30 results per page – infact this to large reults inside same folder
any help
please
Thanks a lot. Looking everywhere for one of these that worked, this code is perfect. Appreciate your addition to hide specific file types as well. Exactly what I needed.
How to display results in limit for 30 results per page – infact this to large reults inside same folder
any help
please
Is there a way to mark the directories in that directory as such.I use words ,letters and it would be helpful if they were marked somehow.This is the best Script of this type I have found.I have looked high and low for this and came across this purely by accident.Thanks Andrew for posting this for others to use
Dear all :
You can choose a certain file only , for example if you want to display “.doc” only without any files maybe exist in that folder, so then you should REPLACE this code instead of gets each entry to be seems as follow:
// gets each entry
while($entryName = readdir($myDirectory)) {
if (strpos($entryName, ‘.mp3’,1) ) {
$dirArray[] = $entryName;
}
}
So, the files of mp3 will be displayed only
and if you want to display files of doc , or html , or wav, or ram , you should replac mp3 with any of them
Zeyad
Zeyad, do you know how to reverse this process so I can Hide mp3 files?
But really i want some one to tell me how to limit this display , if the folder havre large quantities of mp3 files
and want to display 20 files per page when display in browsers
thanks in advance
Just came across this. Brilliant. Just what I wanted and as a beginner in php, a nice intro to some basic functionality.
Thanks.
File size change, bytes to Kbytes!
Replace:
with:
;)
Hello, I get this without modifying the code at all:
Deprecated: Function split() is deprecated in C:\xampp\htdocs\test\.index.php on line 39
I get a new one of those every time I add a new folder, and when I click on hidden folders I get the same line just a bunch of more times.
Read the comments above. ..split() is replaced with explode() in the latest PHP builds.
I guess no one is using the “file type” column which didn’t work for me. It seemed to be printing out the full filename rather then the extension so I added the substr function to count -3 back from the end of the filename and then display 3 characters to the right. New code looks like this.
Hope this helps anyone needing this.
Change
$exts=split("[/\\.]", $filename);
on line 39 to$exts=explode("[/\\.]", $filename);
I just uploaded it here
http://whatshappeningtampa.com/events/
i created a test directory but when i try to acess that it shows an error
anything missing from the code ? or i cant have subfolders
I think i’m having the problem you had but from your example it look like you’ve solved it. I can style the first directory, but once you move to another folder, the styles dont stay, but rather they default back to the ugly standard layout. Can you share how to get my subfolders to share the same styling?
Hey, I get this when I set:
Every time I add a new file, I get a new set of those 3 errors.
Hi!
this is great. Thank you.
Is there a way to have the list sorted alphabetically by default? Not it seems to be sorted by modified date. Is this easy to adjust?
Many thanks!
Is there anyway to keep the styling when you enter a folder on the server?
Did you ever find a solution for this? I’m having the same problem.
BUMP FOR THIS!!
Hi,
I am using this brilliant code for directory listing with thumbnails using imagemagick for PDF thumbnails.
the issue is that each time I use the following loop a new jpg file is created. even if it already there..
Please urgent help required…..
$path =”images/”;
$filename = “$path/$namehref.jpg”;
if (file_exists($filename))
{
$tempimg = $filename;
}
else
{
$result = exec(“convert -density 300 $path/$namehref -thumbnail 150×150 $path/$namehref.jpg”);
$tempimg = “$path/$namehref.jpg”;
//$tempimg = “images/preview.jpg”;
}
//****using for thumbnail display***/
hi, im a total noob about coding. so, excuse my stupid question. where should i put those files? i tried to upload the on the root but nothing is happening.
Thanks for the script, it works well. Is there a way to show the same style after clicking on the folders in the same directory as files?
to keep the same style when open subdirectories, i managed it work for me:
in the beginning of this page set a variable to receive a directory
in the FOR LOOP, i checked the filetype,
if filetype($namehref) == ‘file’
print
if filetype($namehref) == ‘dir’
link back the same page by using <a href=$PHP_SELF?dir =directory
you might want to play with the directory to meet your needs.
I’m having issues getting the sub folders to share the same styling. My root folder looks great, but as soon as I click to another folder I get the defaults back again. Could you explain more about how to build the for loop and share an example. Sorry I’m not the best in php.
Hi!
Could anyone please share a proper solution to keep the styling when adding a new folder?
Thanks a lot and hear ya soon!
yh would you care to post a copy of your script that you used to maintain the formatting when entering a directory. I’ve tried the example that you posted but I keep getting a parse error.
Cheers
A great script.. thank you….it worked first go for me however I have run into an issue that I think relates to the script focusing on file extensions of 3 characters only.
I ran into an issue where I have .docx and .xlsx files located on the server. While it presents them correctly in the list on the page, when I click to download them the Save window defaults to save them as .zip instead of the original 4 letter extension.
Are there any changes to the script you can recommend to resolve this?
thank you in advance
Tim
oowww just realised I get these results only within IE8 but Chrome seems to work fine.
Hi all,
I just deployed this script.
Demo is here http://hopquacuoi.com/kt/
Anyone can help me to embed this script with
1. Delete function (can delete/remove displayed file)
2. Preview function (can preview a file)
3. Alert function. I want to embed a reminder like this http://www.fremeaujewelers.com/reminder/ into.
Many thanks
Tung
Hi Tung
Any chance of a copy of your updated code for this? Its exactly what I’m after for our internal paper pdf system.
Thanks
I’m trying to also password protect this site at manabreakfast.com/commissions and when I add the code to the .htaccess file and upload the .htpasswd file it gives me a 500 error. Is there something else i need to do to password protect this directory and use this styled directory contents?
Hello there, this is great!
One issue though….My browser wont show the file or force download. I get a 403 error. Please help! This is amazingg….
Hy guys,
Thank you a lot for this work
I ‘am getting same warning and try a lot of things to fix it
No solutions
Please help me if you can
this is warning :
Warning:
filesize() [function.filesize]: stat failed for aigle_005.jpg in C:\wamp\www\Tests\.index.php on line 79
Warning: filemtime() [function.filemtime]: stat failed for aigle_005.jpg in C:\wamp\www\Tests\.index.php on line 82
the both functions are not working
Thank you
Hi I was wondering if there is any modification to this script that will force the user to download each file (PDF, JPG etc.) rather than open it in the browser window?
Thanks, and great script by the way!
I just downloaded and extracted all the files individually into my folders that i want to use this in, and i dont see a change, i only see the default index page, is there something i am missing? or did i not change something within the files to make it work that you didnt explain well enough for me, please help, thanks if you reply/e-mail me as well.
by the way, i only know basic HTML coding, but i run my own webserver from my home.
I believe the files you need are hidden files ( files starting with a “.” period. ). Configure your computer to show hidden files and you’ll see the hidden files in the download folder.
first, thanks for the reply!
second, thats not my issue, i use winrar to open the zip, and can see, move, and modify the files, they just wont load in my website, and if it matter im running it with apache 2.2 on ubuntu 12.04 LTS
Do you have php enabled and using the correct chmod settings?
doubt it if thats something extra you have to change, any way to help me with that to see if thats the issue?
Hmmm….Not sure about that one. I loaded the files onto my server and it just worked. Sorry….Good luck.
ok so i got php5 installed now, is there anything else i could try “bud”?
Personally,I have no idea how to set php up on a server.But if you have that done test it to make sure it works.Try a couple of easy php scripts and then move on to this one.
just so you know if using linux to host the server
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart
and i also got it working by point the links on the page to the actual .index.php file, but for some reason it would not point to the file automatically, had to make the link like normal
Using html how to open display directory contents in tomcat server..pls help me
I am trying to find out the exact code to replace so I can search for all files with names starting E05 H06.mp4 I would like to Deliver files only that are E05. Any help would be appreciated
Having the same issue as Jared. Would like to keep the styling within the folders that are listed. Anyway to do that? Yh presented somewhat of a solution but i have no way of implementing that as I am a PHP novice.
Hmm….it could be as easy as putting all of the original folders and files to make this happen in each subdirectory?
Hmm….it could be as easy as putting all of the original folders and files to make this happen in each subdirectory?
…..nope that is way too time consuming and takes a lot when you have a pretty elaborate directory tree structure.
Alright. I did it the hard way. I copied the .index.php file into the sub folders and changed out the link to the sortable.js and the .css file and it worked like a charm. I’m much more fluent with css and html than I am in php. I’m sure there is a better way to do this….but until then I have to use this.
the script is working in my website, but the icons are not working. can some one be so kind as to give the steps to install this script. I am a bit slow on php. the specific step by step instruction will realy help.
You have to make sure the path to the icon images is correct.I use this script in multiple locations but the images for the icons I use the full location address-no shortcuts so that I can use the script this way
Where do you find the path for the icon images. What i did is this:
1. I downloaded the zip file
2. I extract the content
3. I took the content of the file and put all the content in the file on the server that I want to generate links.
4.I directed the page to load on:
http://www.exeple.com/none/.index.php
It works but the images on the left does not appear.
I know I am doing something wrong. This is a freat code. If i dont figure it out, it will be ok, i will use it as it is now. but i will never learn if I dont ask, and I just dont want to half way do something. Your help is greatly appricated. thanks
Don’t forget that the directories have a dot in front of them – .images
If you got rid of that dot in front of the folder them it wont work.I see there are limited icons that come with this script.The css file is where the images are set for the file types.make sure it points to the correct location as I mentioned above
By the way,the page you posted does not show the script you are talking about.There is nothing on that page that I saw was relevent to the script either????????
sorry, but the website was just an exemple is not an active website, sorry for that. I see what you mean about the css file to point to the .images folder. I have not done that. thanks a lot will try it and let you know. thanks again. very helpful.
Hello
I wonder if this code allows you to hide files with. Html or. Php in the same directory as the images
I thank you in advance for help
Tide, I agree. I see people adding code to only show mp3 files or doc files. I would love to reverse that so we DON’T show php files.
Thanks mate! I have removed the “Show Hidden Files” function for security reasons.
Ralph, how did you modify to remove the “Show Hidden Files”?
I tried the solution above (Benjamin September 29, 2010) and got all the individual files, no folders (not what I want) and when I clicked on the show hidden files they were all there so that didn’t work for me.
I tried to use Markdown to place code blocks but it would parse my html and PHP code that was in the code blocks. I am unable to place the code at all in this form ” this forum should stick with bb code no one is going to spend over an hour to learn how to properly use markup and whatever else this forum is using for replies to reply with a few words.” That being said
I commented out the php echo string on the last echo of .index.php
after ?php
Anyway to make it work in all directories and sub directories without having to copy the code into each directory?
Looking to make it work somewhat like this ftp://triad-atlanta.com/
this is awesome , want to know how to give “delete” function to each of these files
Finding this made my day!!! thank you soo much. I am having 1 problem if anyone knows. I added the code
I password protected the directory so each file has a “LCK” file. When i added that extension to the “$forbiddenExts” line but they still show up. If I add “pdf” to the code then the pdf files and the pdf.LCK file are hidden. I only want to hide the LCK file. Any ideas?
I did add “IndexIgnore *.LCK” to my .htaccess file but now that i am using this they show up again. please help!
I’m using this code to create the directory and opening the index.php page in an iFrame so I can show different directories via the menu bar. The problem I am having is that the selected documents are opening within the iFrame when I need them to open in a new window. I’ve added target=’_blank’ to the output table but it’s not working. Any advice?
Please ignore my question. I’ve been staring at this too long and my iFrame was referencing a different file! Rookie mistake! target=’_blank’ works exactly like it should.
I can’t seem to get the returned links to open in a new window or tab.
Adding the target=’_blank’ causes an error that not any of the files load
Any help?
Hi,
First of all thanks for the wonderful script it helped me a lot.
The script is working perfectly, the issue I am facing are
1) I have a big list of files on my server, I want that if a search could be integrated to this script. That would really help me.
2) If its possible to show alphabets at the top so that when some1 clicks them, only files starting with that alphabet will be shown.
Hi,
This has been an invaluable post however I, like a few others here, am looking for a way for this style of display to extend to subfolders. Placing the files in every subfolder is extremely impractical for my use.
If anyone is aware of how to do this, please let me know!
How do I keep from loosing the formatting when I go into a subdirectory?
Thanks for the post,
John
This is brilliant!!
I am currently using it and we are loving it :)
Thanks!!!
Hi, Thanks for this post. It worked for me! But I would appreciate if it included a “delete” button in which i can delete uploaded files.
I have the following error’s when running the code. Can somebody help me figure out what part of the code needs to be changed. I get this error and other just like it for file size. Thanks
Warning: filemtime() [function.filemtime]: stat failed for Combs 2012 Bell TNG.pdf in /home2/combsb/public_html/file_display.php on line 80
Nice piece of code. However I would like to display the time properly. HH:MM DDMMYY . Not too familiar with code like this, so could anyone point me to the place where the date and time is being displayed so I can correct it?
Thanks alot! This really helped me out!!
Removed show hidden file for securuty
Handle subdirectories (now subfolder keep the same style)
http://pastebin.com/edvpqBg5
ps: Sorry, i’ve translate text in italian
Hi “Wilds“,
thanks for the code. But there is a little problem with the time and the size of the files on the subpages. It just works perfectly on the mainpage. On the subpages always 1. January 1970, 00:00 is shown and no size.
Would be very nice if you could check this.
I’ve done an update to the version of the script that wilds released. There were some bugs in his code that made the date and size not appear properly. I’ve also changed and added a few things. You should only have to place this in the root now and all the styles will be applied to sub-folders. The code has been separated from .index.php into a seperate file .engine.php. I also changed and added more icons and file types. There is a header.html and footer.html so you can customize without altering the file associated with the listing.
That’s about it. You can find a demo of it on my site(ish) (it’s not up all the time).
Demo
http://squirrelhouse.no-ip.info/
Here is the download
http://squirrelhouse.no-ip.info/Downloads/PHP/DirList.7z
You’ll need 7-zip for the file
Hi Paul,
would be very nice if you could update your posted links.
Thank you all who have provided examples and tweaks to this code. It’s incredibly helpful.
Is it possible to add a column to the left of each document name that contains a red X that will allow only an admin to delete the file? This red x would only appear when the user is logged in as the site admin.
Is it also possible to add a file uploader that is only visible to the site admin that will place the file in the folder being viewed?
Right now I’m using the script to display the directory content and have the site admin use FileZilla to manage the documents. It would be so much easier to just manage everything through the website.
I discovered a security issue in the version that Wilds submitted (which is what I based mine off of). I’ve corrected the problem and updated both the original DirList.7z and DirList2.7z. For the people who already downloaded my version, you need to either download again or add this code at the beginning of the list_files function in engine.php:
Delete the if statement where it checks $_SERVER[‘QUERY_STRING’] || …
And replace it with this:
Before if the user typed .. or ./ or any other variation, they would be able to view directory listings outside of the server root directory (not read or modify). It looks like Wilds already thought of that, but the code was not working right.
http://squirrelhouse.no-ip.info/Downloads/PHP/DirList.7z
Paul, I too, would like to see your handi-work (DirList7z. & DirList2.7z) utilizing Wilds killer script with ext. header/footer html includes. It appears that squirrellhouse URL has taken a nap… thanks in advance!
Thanks for all your help! i want to implement Paul’s DirList.7z solution, but I can’t download it, the link is OK…
Can someone else send the same script?
Thanks,
I’ve manage to add a delete.png image at the end of each row. Nothing difficult here, but I don’t know how to delete the file when I press the image.
Any suggestions from someone who knows, please ?
@Paul – I also tried your download link – (http://squirrelhouse.no-ip.info/Downloads/PHP/DirList.7z), but failed to download. Could you possible upload to a dropbox etc. Thanks in advance.
I noticed that whenever I try to upload a file with more than 2mb filesize. An error occurs. The file failed to be uploaded.
Thanks – this is very cool!
Related question – is there any way to get (relatively) the same effects without using PHP (or any other server-side scripting)? I recognize the depth of what I’m asking – I’d like to apply a style to an open directory that gets regularly burned to a CD for distribution, without having to keep updating the coding each time the directory contents change.
The files in the directory get updated on a random schedule. I want the end user to see the directory of files, but without it looking like my kids made it.
I love this script.
Except I am finding some flaws in it and I was wondering if someone could please fill in the missing pieces.
The main script is beautiful, but I want to go to a specific directory.
The second script provided by Wilds, which is in italian, works great for displaying another directory in the proper CSS style, but the filesize and date modified does not work properly.
Also for some reason when I change directories, I cannot display or download the file because when I click on it, it wants to give me a directory structure that is different then my directory path.
So if anyone can help, I would be so very happy.
Fixed filesize and date bug: http://pastebin.com/edvpqBg5
Sorry, but I can’t replicate the problem with directory structure.
Hi Wilds, I have some errors with ur script. I’m using it in a site with a lot of files but the issue is that I can’t download files with .exe .jpg or .txt extensions, works fine with rar or zip files. Could you check this please. Thanks.
Nevermind, is working fine. my server was the problem. thanks.
BTW. there’s a way that instead of displaying “directory contents” (contenuto) it shows the name of the current directory ??
Hello, I’m using ur code. I have a problem here, if a folder has character like: ” ,+’ etc it won’t display the files inside it, so I should rename/remove the character. how to fix this?
Hi. I understand files can be hidden ie (.) before the filename but I have a file in the same directory which I cannot use the (.) before. Is there any code to add which I can specify to hide a file regardless of whether it has a (.) infront or not?
Thanks
Ok, now it shows the curren directory name: http://pastebin.com/SjbjbqPR
Great !!! Thanks
I love this script.
But can I show Dictionary (sort A->Z), then file (sort A-> Z)
http://pastebin.com/FTTzpLM1
Works like a charm! Now there’s just one more thing left – how can I add a “download” button which forces the download instead of opening it in the browser?
Has anyone figured out a way to allow for certain users to delete files? Can I add this script to a page with restricted access so they can delete old files. I’m trying to build a site that allows different chefs to upload their menus as they change. I’ve created the members login section and figured out a way for each chef to upload PDFs. I would like for them to be able to delete older menus from their individual directories. This delete function would be restricted to each chef so they can only delete their own files
I can’t get this to work on any Android devices. It works perfectly in all recent browsers and Apple products but not on any of the Samsung phones I have tested. Anyone else have the same issue?
superb code but to display the same styles in sub directories i have to place all the files into other sub directories as well ;-)
I got this working sometime ago but have returned because I am looking to see if anyone have ammend or added the code to display an images demensions in the list of files
Okay,I found this snippet on this ” php snippet” section.
How can this be added to the styled directory contents script .I am a complete novice and have no idea where to add it?
Any help would be greatly appreciated
I got it working on my own-
First time I was able to do something like this on my own with php
cool……..
Hi Bud,
I realize it was a while ago, but can you share what you did to make the image dimensions display work?
I have a directory with several subfolders. The parent is username and password protected with the plesk panel app. When I put this code in the parent directory, it seems to conflict with the login credentials and gives me a 404 error for the page. If I put in my old directory indexing code in the parent directory, it looks pretty ugly but when I click on the subfolders, those work as this post states since I have this post’s files in each directory.
Does anyone have any tips and fixing the login conflict in the parent?
Thanks
Bryan
Nevermind. I went ahead and just coded up an html page for the parent folder and that solved my issue. Thanks though
Hi. After downloading the files, where is the best place to put the .images folder?
Sorry, just to add to my last post. When I load the browswer I get “Translate” from Spanish.. Is there an english version or can I edit the scriprt.
Thanks
I need to modified this code to prevent the showing of XML and MHT files
Also, want to sort by date.
Love the script, but need to change directorys. I’ve tried this
// $myDirectory=opendir(“.”);
$myDirectory=opendir(“/var/www”);
but only get the style display page with out any results. Is there a simple was to
switch the directory from “.”
I guess it’s always good to answer your own question post.
$path = “/home/david/Downloads”;
// Opens directory
// $myDirectory=opendir(“.”);
$myDirectory=opendir($path);
Any directory path that is placed in $path = ” “. Will now be displayed
Trying to exclude certain file extensions. When I use Benjamin’s code above, I get a bunch of unknowns instead of file names.
If I use zeyad’s code above, I get a page without any files. No matter what extension I put in it doesn’t show any files.
Help please…
I have the exclude file extensions working but…I lose the formatting when I go into sub directories
Can someone tell me exactly what controls that in the code?
I had to put the files in each sub-directory to get it to work right.
Ok, I lied. Here are my issues:
Cannot filter out file extension that I do not want
Would like to sort by date
The icons do not show next to the file name.
i would liketo create a link to show the parent folder… but not allow to show hidden files.. like the.htaccess .index.php…..
Is this question already solved?
I also want to show the parent folder, but NOT hidden files and NOT hidden switch.
Thx
Cody,make sure the path to the images used in the file is correct.I had to fix that when I did this too.
how does the images affect if i see the .htaccess file..
How to replace spaces for %20 in directories that have spaces in name ?
E.g: “www.mysite.com/?index/my images”
I want it like this “www.mysite.com/?index/my%20images”
Thanks, it worked for me.. with out any changes
File images are only working in my root directory. What file and line(s) of code do I need to edit to get the file images to show up in sub-directories as well?
Answered my own question!
Turns out sub-folder icons are working. My site mainly has PDF files. The code has no PDF icon code in the css. I just needed to add the code lines for PDF files!
SOLVED!
I am wanting to use this for a video library, so I have $myDirectory=opendir(“Videos”); instead of $myDirectory=opendir(“.”);.
However, when I click on the link to the file I get a 404 error, and when I look at the 404 error page I notice that it says the requested URL is http://localhost/“name of video” instead of http://localhost/Videos/“name of video”
How can I correct that?
Is there a way to show the list without showing the parent folders? “.” and “..”?
If you remove
|| ($currdir != '.' && $dirArray[$index] == "..")
fromif (substr("$dirArray[$index]", 0, 1) != $hide || ($currdir != '.' && $dirArray[$index] == "..")) {
It should remove the parent folders.
That’s what worked for me anyway.
how to rename the directory files name ??plzzz help me
has no way to sort by date, by default?
Hi
I am trying to use this code multiple times on the same webpage and I get wierd results.
The first time it displays the files from the folder correctly.
The second time it displays both the files from this folder and the first folder.
Then third time you get the files from all 3 folders.
How can I stop the files being repeated?
Thanks
Everything works beautifully in Chrome however IE8 does not display any icons.
Is there anything I can modify to make it more compatible with IE8? Unfortunately I’m forced to support this browser.
Thanks and awesome job!
This is awesome!
just one error I’m seeing, if your filename has an apostrophe in it the file icon will default to the document icon.
For example, an audio file named: John’s Song.mp3 will not show the audio icon because of the apostrophe.
Any idea how to fix this?
Does anyone know how to trim the names of folders and files, for example only show the first 25 characters of the filename.
Thanks in advance
Is it possible to show different folder icons for directories?
For example I would like a different icon for my photos directory, my video directory my zip directory etc..
Many thanks for any help, Kim.
How do we sort the files by last modified date (by default). I would like the files to be sorted by date when the page is opened. Thanks.
hi
how to implement a style for all subfolders in the file?
thank you
Thanks for this great script. :)
I’ve got a minor problem. I used the modified version from Wilds. Filesize only shows the word “bytes” and last modified only displays “Jan 1 1970 1:00 AM” on all files. How can I solve this?
for warning : Warning: filesize() [function.filesize]: stat failed for….
try this : $dirArray[$index]=$_SERVER[“DOCUMENT_ROOT”].”/dash/welcome/gbr_email/”.$dirArray[$index];
for warning : Warning: filesize() [function.filesize]: stat failed for….
try this : $dirArray[$index]=$_SERVER[“DOCUMENT_ROOT”].”/YOUR FOLDER/”.$dirArray[$index];
I recive this error when try to click on my document folder :
Forbidden
You don’t have permission to access /personale/vedi/APPO/ on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
any idea?
Thanks Fabrizio
Hi, I really like the code and the modification that wolf did to it, But id like to know if anyone has been able to include javascript to create a button or slider that switches between list and grid view. And how can i change the default folder without getting errors.
By default folder, I mean i have the page as index but i’d like to display a different directory in my index page.
Hi, i have it all working lovely for local files but i would like to connect to a network folder that uses sftp. How easy is this to do as im new to PHP and a copy & paste job would be great.
Hello,
I am using this script for watching video’s from my website. But when I use target=”_blanc” it also opens the ‘previous directory’ in a new tab. Is there any way to only open files in a new tab?
Thanks in advance.
Regards, Alex
@pedro
Quote
Does anyone know how to trim the names of folders and files, for example only show the first 25 characters of the filename.
Find
// Gets favicon.ico, and displays it, only if it exists.
Add Above
// Trim the filename titles to 25 chars
$name = strlen($name) > 25 ? substr($name, 0, 25) . ‘…’ : $name;
You can alter the amount to show by changing the 25 x2 above to suite your needs.
I have a website built using html5 not php, but would like the same type of styling on directories.
Is that possible?
cheers
Is php enabled on the server you have?
Neat Code works like a charm . to stop it giving the option of diplaying the hidden files I just removed the line of code that does that.
What I am wondering is how could you make it so it only shows the file names and make the text larger if it is being viewed on a cell phone or make it responsive to the size of the screen ( without the file “Type” , ” Size” and “Date Modified “
Thanks a lot.
Added background-size: 16px 16px; in order to avoid a display bug with favicon images bigger than this size, also checking some folders to find the favicon :
$chemins_favicon = array(
“img/”,
“images/”,
“”
);
Hello,
I’d like to know if and how i can add a script to a selected item in the list, Perhaps a script to send the file through email or delete it. Any help would be appreciated. Please comment if you do not understand.
Very cool script. PHP is all very new to me but thanks to all the comments and suggestions I was able to get the script up working the way that I wanted.
A change I made was to the box size, I didn’t want it exploding across the screen. You can control this in the .styles.css under the tag #container.
#container {
width: 800px;
margin-left:auto;
margin-right:auto;
box-shadow: 0 15px 10px -5px rgba(0,0,0,0.5);
position: relative;
background: #dbe7f6;
}
You can add width, margin-left, and margin-right parameters to define the box the way you would to see it on the screen.
Hi, nice script, it’s working perfect! I need to open directories in new tab or new window. How can I do this? I don’t know PHP :(
Best regards!
Hello!
I’m not a developer, but Im trying to follow the steps to make the demo files work for me. What I did was just copy the hidden files to the folder I’m trying to list files, but nothing happened. I tried to access it as local machine and maybe this is the problem. What I need to do is to embed the list of files in my website. For that, I’m using iframe to make it happen. It worked with google drive, but is not working in local machine. Any ideas? Thanks!
Greetings.
I used the code and is working like a charm. but when i view the files and click them it doesn’t start downloading, i noticed the file path is not the real one when i click them, only work if i “right click and save as”.
Is there a way to solve this?
Thanks in advance.
Please can someone tell how can I put an add unit within the listing… say like after 5 folders or files I have and adsense unit…
Nice discussion – Incidentally , people require a NY DTF ST-330 , my business partner filled out and faxed a template version http://goo.gl/Cw08AX
Thanks for amazing script, it worked without problem however I was wondering if it is possible to make this recursive to list even subfolder content without uploading the files on all folders plus breadcrumb.
replace line 33 with this :
$return.= ‘DROP TABLE IF EXISTS ‘.$table.’;’;
How to display each of the files MD5 or SHA?
Great people please i want to embed a pdf viewer in my php application, i added the code from the get file names section of the php code i got from this site its not displaying he documents
// Gets File Names
//
$name=$dirArray[$index];
$namehref=’/achs0/ViewerJS/PDF_findfont(p, example.local.css, encoding, embed).pdf/($dirArray)'[$index];
This is a wonderful solution to a dilemma that has plagued me for quite some time; I’m grateful! I am displaying this within a mobile app, where there is no built-in navigation. Is there any way to add a “go up one level” button?
The page in question is at http://www.presum16.com/seminars.
Hi! Is there any way to protect wit password?
Thanks
Hi,
Great script !
PDF files do not show with an icon, so …
I have added an image “pdf.png” (16×16) into .images
and added into :
.style.css
table tr td:first-of-type a[href$=”.pdf”],
{background-image: url(./.images/pdf.png)}
But it does not work,
please can you correct me ?
Thanks ;)
Hey everyone,
Im loving this code
Anyone knows how to keep the “current directory” and “Parent Directory” shown at all times?
Thank you very much, hope to get answers!
This is GREAT!!!
I just have one question, how do I hide folders from displaying on the list?
Thx for the great code …
I slightly modified the code to allow the display of a subfolder (I use it to display log files)…
So just added a “$myDir” variable and added it where there is the “$dirArray[$index])” except for the “$name” variable ..
Like this :
Your code was a great help…
can u tell me how to pre sort on date modified…so that i can get the latest uploaded file in first row….
thanks to Wilds
http://pastebin.com/FTTzpLM1
sucses edited file sort by date modified
have tested edit line 63
sort($dirArray);
edited to
sort($dirArray, “cmp”);
How can you password protect the initial listings?
Not showing cyrillic(
How can fix this?
I see most questions answered by reading the thread in full. @benjamin provides wonderful solution. Deleting, downloading requires little programing knowledge. Opening from new target works well too.
It works for me in the top directory where the dot files are, but the directories within revert back to display in ordinary Apache dirlist. Is it supposed to work in subdirectories? I’m trying the last zip posted by the original author, https://css-tricks.com/examples/DisplayDirectoryContents.zip, I think that from 2012.
I confirm that if I copy the dot files into all subdirectories, then they display beautifully.
I do not understand message by Galadriann above. I mean, he doesn’t give full working file, and I can’t get that trick to fix problem.
Thanks awesome! Thank you so much.
But i have a small questions.
How can i do pagination this file list?
Thanks
I feel bad asking a question about something offered up so long ago, but if I could get this to work it would be extremely helpful on a project currently underway. I’m pretty sure that I’ve done everything as directed (and using the provided files), but all I get is an internal server error so I don’t even have an idea about where to start troubleshooting. I’m trying to execute this on a WordPress site, could that be an issue?
-Thanks
Well, simply moving the whole thing to another server fixed whatever issue I was having. Thanks for this great resource.
great script but i can’t for the love of me get the sorting to become by modified date and whatever new is added to the folder appears on top, any ideas on how to do this? I’ve been playing around with usort but nothing gets sorted the way i want it to.
Did you ever get an answer to this? I too would love to change it so the default sort is ascending.
I also really need it to sort by date modified by default . There must be a way!
Sweet, 7 years later and the code worked beautifully. Installed to a directory running openwrt, uhttpd on an embedded device. Thanks
Hi great script but can anyone help me to fix a problem the date and time is displaying wrong of the files all files has same date and time all files shows dec 31 1969 at 7:00 pm
Hi Vicky,
seems you’re not using the latest version … I used Wilds’ latest one of his post “comment# November 7, 2013 / Fixed filesize and date bug” with the link
http://pastebin.com/edvpqBg5
Thanks to everybody creating and updating this wonderful script – you all did a great job!
Here you go : all fixed up
https://pastebin.com/yxCWvmir
Nobody noticed the difference on modified time of files ?
On .index.php insert between:
the follwing line:
Here is the list of PHP supported timezones: http://www.php.net/manual/en/timezones.php
This has worked great for years. Thanks.
Now moving from Windows Server 2012 to WS2016 the subdirectories no longer load contents. And I needed add .index.php as a default file to get the parent directory working.
Any ideas why sub directories would be throwing a “403 – Forbidden: Access is denied.” error?
I’m not sure if there’s an easier workaround but I copied all the contents from the zip file into each dir I wanted to display.
Great script. I set me directory outside of the root, but any links are referring back to root. Anyway to set the links to the CWD?
Very nice script. Cleanly solves a common problem.
Wishlist !
Can the file extensions be made case insensitive. So that .pdf and .PDF files will both display as “PDF Document” ?
Same for all other file types.
CASE INSENSITIVE FILENAME/S
I’m a php newbie, more familiar with perl.
The following line just before the switch to prettify the file type/s seems to work as intended.
$extn = strtolower($extn) ;
Any obvious problems likely to emerge from this small hack ?
Otherwise, HTH
Is this a bug ?
Seems this script won’t work if there’s any hash symbol (#) in the filename/s.
Not sure how PHP deals with hash symbols in filenames.
I am facing problem in downloading files and viewing sub folder.
$path=”D:”;
// $myDirectory=opendir(“.”);
$myDirectory=opendir(“$path”);
$name
$extn
$size
$modtime
“);
can css works with sub folder too. If not how can it be done.
How do i view this in my browser and add my ftp client to it??
Has anyone figured out a work around for files containing an apostrophe? Such as “It’s a wonderful day.mp3” The url path ends after the t when I hover the mouse over it and if I click the file, I get the “404 Not Found” error.
Just implemented this to give music students readable lists of play-along tracks. Brilliant. First time ever with php and it worked instantly. Easy to edit and import my site style.
I was able to install from the zip file and main page of web site works as expected. Problem is with subdirectories still using the default html index style instead of style from top level.
@Wade Williston –
I used http://pastebin.com/FTTzpLM1 and it works well with subdirectories (with some tweaks).
I would like to know how to add a breadcrumb trail to the top that adds each directory title as you click through the subdirectories. Thanks!
Tks a lot! For you and the other users with comments for help.
Hi, look great.
There is a bug if there is a ‘#’ in a filename. Items not replaced by %23. Could point me in the right direction to find that problem ?
Thanks.
I just added $namehref = str_replace(“#”,”%23″, $namehref); just before the echo command in .index.php. It’s working but it doesn’t look like the proper solution…
Awesome trick! This is almost just what I needed for my ongoing project.
I’m quite new to php, so I was wondering if there is a way to implement this with bootstrap, so it makes a grid of all the folders in the directory?
Anyway to make it so that it shows this for any folder that is clicked on without needing to copy the files into each and every folder ?
i.e so having one .index.php in say /var/www/ that will work all the way though /var/www/html/folder/folder/folder/folder etc
Hi.. How to hidden button Show and hide files on directory. I’m afraid that I will be able to see the file that I hid later in that folder
Worked exactly as advertised. I had to tweak a few colors, but otherwise fabulous.
If I wanted the user to be able to move files, (Ex. Drag a file into a folder) how would I go about implementing this into your styled directory view.
Thank you very much! I did’nt succeed in using as given in archive (file with dot at begin don’t work on my shared php website), but with just some changes in index.php, it is ok ;).
That is a good tutorial! I also want to know that is there anyway to apply this css rule to all the directories in the server?
PHP Contains This:
But error message appears:
Pls help
This program is so close to being really good.
It is very hard to read through the comments and try to figure out what to down load and what to patch-change to make it work as most people would like it to work I feel.
I found I had to copy .index.php to every sub-dir to make that sub-dir a functioning directory.
I tried patching the show-hide hidden files text-flag so that I could set it permanently for “don’t show hidden files”.
I found in my experiments that I created a “php_errorlog” which showed up in the files listings. This needs to be suppressed in some sort of exception listing in the set up.
And you need some sort of reverse navigation like a breadcrumbs system.
If you can do this, you have one sweet piece of code.
I wonder if anyone has done this or if “Chris and team” can sort this out.
If you can, add a credit link to the bottom of the page, if you need readers, and a bit of traffic juice.
I am a 76 year old that have forgotten most of what I ever learnt since getting into computers in 1975, as most of my get up and go, has got up and went.
Please, do your self a favor, get this right, then promote yourself and your business.
support2020 at dontronics.com
Cheers Don…
The only thing missing is a search box, other wise its perfect…
Im new to PHP, is there a way to add a search box to this?
Hi,
I have been using this great script for a while.
My web host has just told me that they are stopping php 7.2 support.
Could someone post a php 8 version of the script, if possible with the tweaks that have been made to it?
I am sure that it woold be a boon for a lot of people.
Many thanks
Take care
Andy
Hi,
I’m sure this request has been solved by now.
I’d like the parent directory link to be shown at all times while hidden files remain hidden.
Can someone please post a working solution and README.
Thanks,
Paul
For parent directory link, in the .index.php file :
<a style='color: ;’href=”../”>Parent Directory
Is it possible to have this page shown as you drill down into sub folders (but block the top level folder access)?
i.e, we have sub-folders that we deploy to certain users, but don’t wish them to be able to see ALL the folders availiable, i.e, if they go to the parent they’d just see a blank page or ‘Nothing to see here.’ Error.
Hi, can you reupload your version pls?
Thnaks
Thanks for all your hard work!! The breakdowns on how to resize or reposition in the middle of an IGTV tutorial are a little redundant HOWEVER~ Lists like this are absolutely invaluable!!! It can be overwhelming with how many resources are out there and where to spend the bucks. Having a pro like yourself break it down based off of experience can save lots of time. Keep up the Great Work.
Any idea why my files aren’t showing up from the “.” directory? I assume the .index.php file is housed in the same directory as the files you want to be able to click and open? Is that a .htaccess issue?
Amazing – It worked right out of the box :-)
can someone share the version fix with eternal folder path and subfolder with template pls?
Thanks