Quote:
|
Originally Posted by epheterson
I have an upload directory on my site, it has become far too large to load the entire directory listing to download one file,
|
Ummm, why don't you page the output? Here's some generic paging code that's meant for use with mySQL, but could easily be modified to work with the directory listing that HockeyGod wrote.
---------------------------------------------
// set rows per page
$rows_per_page = 5;
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
// Identify how many database rows are available
// This code will count how many rows will satisfy the current query.
$query = "SELECT * FROM users WHERE user_id = $something";
$result = mysql_query($query);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
// Calculate number of $lastpage
// This code uses the values in $rows_per_page and
// $numrows in order to identify the number of the last page.
$lastpage = ceil($numrows/$rows_per_page);
// This code checks that the value of $pageno is an integer between 1 and $lastpage.
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
// Construct LIMIT clause
//This code will construct the LIMIT clause for the sql SELECT statement.
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
// Issue the database query
// Now we can issue the database qery and process the result.
// get the users who exist and have entries in the 'trv_ustat' table
$query = "SELECT * FROM trv_users, trv_ustat WHERE trv_users.user_id = trv_ustat.id ORDER BY user_id $limit";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
//... process contents of $result ...
(....do something here with your code....)
// Construct pagination hyperlinks
// Construct the hyperlinks which will allow the user to select
// other pages.
if ($pageno == 1) {
$first_prev = " FIRST << PREV ";
} else {
$first_prev = " [<a href='{$_SERVER['PHP_SELF']}?pageno=1' class='nav'>FIRST</a>] ";
$prevpage = $pageno-1;
$first_prev = $first_prev . " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage' class='nav'><< PREV</a> ";
}
// Next, show the user his current position in the sequence of available pages.
echo " ( Page $pageno of $lastpage ) ";
// This code will provide the links for any following pages.
if ($pageno == $lastpage) {
$next_last = " NEXT >> LAST ";
} else {
$nextpage = $pageno+1;
$next_last = " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage' class='nav'>$NEXT >></a> ";
$next_last = $next_last . " [<a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage' class='nav'>LAST</a>] ";
}
print <<<EOM
<center>[ Page $pageno of $lastpage ]</center>
<table width='100%' cellpadding="1" cellspacing="1" border="0>
<tr align="center" bgcolor="$headcol"><td width="25%" valign="middle"> </td>
<td align="center" valign="middle">
$first_prev $sep_char1 $next_last
</td>
<td width="25%" align="right">
<a href="$good_login" class="nav">$back_to_homepage</a></td>
</tr></table>
</center><br>
EOM;