Help - Search - Members - Calendar
Full Version: Listing File Names As Links From A Folder
Zymic Webmaster Forums > Web Design & Development > Client Side Scripting > HTML and CSS
GeorgeT
I´m looking to create links from files stored in a folder (a function that takes the file names and create the links list at the page) using html, without making the links 1 at the time... I hope I make my point English is not my mother language…

Thanks
IamShipon1988
I do not think this is possible with just HTML unless you use iFrame. HTML is just mark-up language used primarily for front-end. You can accomplish this using php with the code below (adopted from xFunda). You might not want to use tables. Or you can download the Directory Indexer by CeleronDude.
CODE
<?php
/*
function that reads directory content and
returns the result as links to every file in the directory
also it disply type wheather its a file or directory
*/
function DirDisply() {

$TrackDir=opendir(".");

while ($file = readdir($TrackDir)) {

if ($file == "." || $file == "..") { }
else {
print "<tr><td><font face=\"Verdana, Arial, Helvetica, sans-serif\"><a href=$file target=_blank>$file</a></font> </td>";
print "<td>  ".filetype($file)."</td></tr><br>";

}
}
closedir($TrackDir);
return;
}

?> <b><font face="Verdana, Arial, Helvetica, sans-serif">Current Directory Contain
Following files and Sub Directories...</font></b>
<p>
<?php
@ DirDisply();
?>
Banjo
For this line here:
CODE
if ($file == "." || $file == "..") { }

Would it not be better to use a if not statement ?
IamShipon1988
Yes it is, but this is just a simple script to load from the current directory. Didn't do a review on this before posting.
ITchimessmo
<?php

if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Files:\n";

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
int count=0;
/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
count++;
}

closedir($handle);
}
?>

It will read your all file create link on all these files.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.