Boas, eu tenho o código abaixo que tirei de um site, mas gostaria que me ajudassem: O problema é o seguinte, eu quero que ele leia apenas determinada pasta, estando como está neste momento ele lê-me todas aspastas existentes no servidor, mas não é isso que pretendo. Este código é muito bom pois deixa que se mexa nos ficheiros. Por debaixo vou colocar outro código que já lê determinada pasta, mas eu não consigo fazer com que me dê os links dos ficheiros. <?php
function showContent($path){
if ($handle = opendir($path))
{
$up = substr($path, 0, (strrpos(dirname($path."/."),"/")));
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<tr><td><img src='style/file2.gif' width='16' height='16' alt='file'/> <a href='".$file."'>".$fName."</a></td>"
.""
."";
} elseif (is_dir($file))
{
print "<tr><td colspan='2'><img src='style/dir2.gif' width='16' height='16' alt='dir'/> <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>";
}
}
}
closedir($handle);
}
}
if (isset($_POST['submitBtn'])){
$actpath = isset($_POST['path']) ? $_POST['path'] : '.';
} else {
$actpath = isset($_GET['path']) ? $_GET['path'] : '.';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%">
<?php
showContent($actpath);
?>
</table>
</div>
<div id="source"></div>
</div>
</body>
Este já lê a pasta que desejo, mas não consigo fazer download dos ficheiros.
<?php
$mydir = dir('c:/apache/htdocs/legendas/');
while(($file = $mydir->read()) !== false) {
echo "$file<BR>";
}
?>