I am working on this little file manager project, I know, there's lots out there. However, I couldn't find one that paged the results that didn't use a DB. Now that I have it set up (works great), I'm not sure how to define the files and not mess up the paging - so that if it's a folder you can open it and work with the files, a photo you can view or delete it and if it's a .txt, .php. etc. you can edit it.
So it would be listed like:
SUBFolder OPEN | DELETE
something.jpg VIEW | DELETE
something.txt VIEW | EDIT | DELETE
Here is the script so far
<?php
if(!$_GET['start']) {
$start = 0;
} else {
$start = $_GET['start'];
}
//Excluded files and folders list separated by commas
$exclude_files = array(".htaccess","whatever");
$ifiles = Array();
//Path to folder you want to list will list subfolders unless in excluded files list
$path = '/demo';
$handle = opendir($path);
//Number of items per page
$number_to_display = '9';
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !in_array($file, $exclude_files)) {
sort ($ifiles);
$ifiles[] = $file;
}
}
closedir($handle);
$total_files = count($ifiles);
$req_pages = ceil($total_files/$number_to_display);
echo "total files = ". $total_files."<br>";
for($z=0; $z<$number_to_display; $z++) {
$vf = $z+$start;
if ($ifiles[$vf] != "")
echo "<a href=\"". $ifiles[$vf]. "\">". $ifiles[$vf] . "</a>\n";
echo "<br>";
}
echo "<br>Req Pages = ". $req_pages. "<br>";
echo "<a href=\"?start=0\">First</a> |";
for($x=0; $x<$req_pages; $x++) { ?>
<a href="?start=<? echo $x*$number_to_display; ?>"><? echo $x+1; ?></a> |
<? } ?>
<a href="?start=<? echo ($x-1)*$number_to_display; ?>">Last</a> |
Also, just so that everyone knows, I don't ask for advice if I haven't worked on it until my brain is mush. I want to thank everyone for being so helpful and if anyone wants to use this code go right ahead.