Web Hosting Talk







View Full Version : Pages PLEASE HELP


Jeff182
05-10-2003, 11:26 PM
What I want to do is use this simple code

<?php
if ($dir = @opendir("./"))
{
while (($file = readdir($dir)) !== false) {

if ($file == '..' || $file=='.' || $file == '.htaccess' || $file == 'index.php') {
echo '';
} else {

echo "<a href=\"$file\" target=\"_blank\">$file</a><br>\n";
}
}
closedir($dir);
}

?>

That will list a directory but I want the files in the directory to be displayed 10 files per page and I want the links automatically to genarate at the bottom of the page, could anyone help me out?

CreativeLogic
05-11-2003, 12:11 PM
I'm not sure how good this is, but you can try it. I didn't test it. So I'm not even sure if it works!
<?php
if ($dir = @opendir("./"))
{
while (($file = readdir($dir)) !== false) {
if ($file == '..' || $file=='.' || $file == '.htaccess' || $file == 'index.php') {
echo '';
} else {
$files[] = $file;
}
}
closedir($dir);
}
sort($files);
for($x=0;$x<=9;++$x) {
$tempfile = $files[$start+$x];
echo "<a href=\"$tempfile\" target=\"_blank\">$tempfile</a><br>\n";
}
if($start-10>=0) {
$tempstart=$start-10;
echo "<a href=\"".$PHP_SELF."?start=".$tempstart."\"><< Previous</a><br>\n";
}
if($start+10<count($files)-1) {
$tempstart=$start+10;
echo "<a href=\"".$PHP_SELF."?start=".$tempstart."\">Next >></a><br>\n";
}
?>