Page 1 of 1
Display folder contents as clickable links?
Posted: Thu Apr 10, 2008 7:14 am
by deBassMan
Hi All
I need to display the contents of a folder (i.e all files that match a four character prefix).
The files may include .pdf, .doc .jpg etc.
I'd like to display the filenames as clickable links which, when clicked would open and display the file (using associated applications)
Would anyone have an example of a script that might enable this?
many thanks for your time and expertise ...
scott
Re: Display folder contents as clickable links?
Posted: Thu Apr 10, 2008 9:37 am
by pedrokas
this is the way i made for a folder of pdf's!
Code: Select all
function comparar($a, $b)
{
return strnatcasecmp($b["1"],$a["1"]);
}
$default_dir = ".";
$dir_lista = array();
$dir = dir($default_dir);
while($file = $dir->read())
{
if(0 != strpos($file, '.pdf'))
{
$ultmod=filemtime($file);
$dir_lista[]= array($file,$ultmod);
}
}
$dir->close();
usort($dir_lista, "comparar");
$arraynum= sizeof($dir_lista);
$i =0;
while($i<$arraynum)
{
$corLista=$dir_lista[$i];
$corFich = $corLista[0];
$corTempo = $corLista[1];
$corDate= date("Y-m-d",$corTempo);
$nome= substr($corFich,0,-4);
echo "<tr>";
echo "<td align=\"center\" valign=\"middle\"><div align=\"left\" class=\"col\">( <span class=\"style4\">$curDate </span>) <a href='$curFich'><strong>$nome</strong> </a></div></td>";
echo "</tr>";
$i = $i + 1;
}
hope it helped!
Re: Display folder contents as clickable links?
Posted: Thu Apr 10, 2008 9:48 am
by pickle
Code: Select all
<?PHP
/* The full, absolute path to the directory */
$file_system_dirname = '/path/to/directory';
/* The part of the path that's below the web root */
$web_dirname = '/to/directory';
chdir($file_system_dirname);
$all_files = glob('*');
natsort($all_files);
foreach($all_files as $filename)
{
echo <<<LINK
<a href = "$web_dirname/$filename">$filename</a>
LINK;
}
?>
Re: Display folder contents as clickable links?
Posted: Fri Apr 11, 2008 9:20 am
by deBassMan
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi there
and thanks for the replies ...
here's how i did it ....
Code: Select all
foreach (glob("*.*") as $filename)
echo "<a href=\"".$filename."\">$filename</a><br/>";
}
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.