Hello, I am fairly new to php. I am trying to take multiple .gif images from a directory, and display them, 10 per page, with pagination. I want page number links like those on Digg or Youtube (i.e. 1 2 3 4 5...11). I also want each image displayed to link to a new page displaying the corresponding code for a user to use that image (i.e. a text area with <img src="http://image(x).gif">), without having to create multiple new pages for each individual image code. I am looking for something similar to THIS. Each image in the directory is named graphic1.gif, graphic2.gif, graphic(x).gif etc etc.
So far i have this:
PHP Code:
<?
function dirList ($directory)
{
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// keep going until all files in directory have been read
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..')
$results[] = $file;
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
function file_extension($filename)
{
$path_info = pathinfo($filename);
return $path_info['extension'];
}
$totalresults = dirList('animations');
$alength = sizeof($totalresults);
$gifresults = array();
for($i=0; $i<$alength; $i++){
if(file_extension($totalresults[$i]) == "gif"){
$gifresults[] = $totalresults[$i];
}
}
$number_per_page = 10;
$pages = ceil(sizeof($gifresults) / $number_per_page);
$current_page = $_GET['p'];
for($i=0; $i<$number_per_page; $i++){
$x = ($current_page * $number_per_page)+$i;
echo "<img src=\"/graphics/animations/" . $gifresults[$x] . "\" />" . "<br />";
}
echo "<a href=\"?p=".($current_page-1)."\">Previous</a> | <a href=\"?p=".($current_page+1)."\">Next</a>";
?>
Any help is much appreciated.
Thanks.
B.
|