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
Display folder contents as clickable links?
Moderator: General Moderators
Re: Display folder contents as clickable links?
this is the way i made for a folder of pdf's!
hope it helped!
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;
}
Re: Display folder contents as clickable links?
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;
}
?>Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Display folder contents as clickable links?
~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 ....
~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: