【php开源代码栏目提醒】:网学会员鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“36.1.lib_photo_gallery.php”一文,供大家参考学习
<?
/**
* Simple php photo gallery, SAJAX
*
* Common functions used in index_sajax.php and index_meta_sajax.php
* skelly 30060404
*/
/*
* Find a list of images in /images and provide thumbnails
*
* Called using Sajax
*/
/*
* Find a list of images in /images and provide thumbnails
*/
function get_table ( $limit_start = 0, $limit_step = 5 ) {
$images = get_image_list('images');
// Append navigation
$output = '<h4>Showing items ' . $limit_start . '-' .
min($limit_start + $limit_step - 1, count($images)) .
' of ' . count($images) . '<br />';
$prev_start = max(0, $limit_start - $limit_step);
if ( $limit_start > 0 ) {
$output .= get_table_link('<<', 0, $limit_step);
$output .= ' | ' . get_table_link('Prev',
$prev_start, $limit_step);
} else {
$output .= '<< | Prev';
}
// Append next button
$next_start = min($limit_start + $limit_step, count($images));
if ( $limit_start + $limit_step < count($images) ) {
$output .= ' | ' . get_table_link('Next',
$next_start, $limit_step);
$output .= ' | ' . get_table_link('>>',
(count($images) - $limit_step), $limit_step);
} else {
$output .= ' | Next | >>';
}
$output .= '</h4>';
$output .= '<table class="image_table">';
$columns = 5;
foreach ($images as $index => $image) {
// Begin directory listing at item number $limit_start
if ( $index < $limit_start ) continue;
// End directory listing at item number $limit_end
if ( $index >= $limit_start + $limit_step ) continue;
// Begin column
if ( $index - $limit_start % $columns == 0 ) {
$output .= '<tr>';
}
$thumbnail = '<img src="images/thumbnails/' . $image . '" />';
$output .= '<td>' . get_image_link($thumbnail, $index) . '</td>';
// Close column
if ( $index - $limit_start % $columns == $columns - 1 ) {
$output .= '</tr>';
}
}
$output .= '</table>';
return $nav . $output;
}
/*
* Get the image, along with the meta data and simple navigation
*
* Called using Sajax
*/
function get_image ( $index ) {
$images = get_image_list ( 'images' );
$output .= '<h4>Viewing image ' . $index . ' of ' . count($images) . '<br />';
if ( $index > 0 ) {
$output .= get_image_link('<<', 0);
$output .= ' | ' . get_image_link('Prev', $index-1);
} else {
$output .= '<< | Prev';
}
$output .= ' | ' . get_table_link('Up', $index, 5);
if ( $index < count($images) ) {
$output .= ' | ' . get_image_link('Next', $index+1);
$output .= ' | ' . get_image_link('>>', count($images));
} else {
$output .= ' | Next | >>';
}
$output .= '</h4>';
$output .= '<img class="full" src="images/' . $images[$index] . '" />';
// Uncomment for metadata
/*
$output .= '<div id="meta_data">';
$output .= get_meta_data( $images[$index] );
$output .= '</div>';
*/
return $output;
}
/**
* Parse xml file and return data
*
* This is the absolute simplest xml structure... all of the meta data is stored
* as HTML inside of a CDATA tag.
*/
function get_meta_data ( $file ) {
// Using getimagesize, the server calculates the dimensions
list($width, $height) = @getimagesize("images/$file");
$output = "<p>Width: {$width}px, Height: {$height}px</p>";
// Use SimpleXML package in PHP_v5:
// http://us3.php.net/manual/en/ref.simplexml.php
$xml = simplexml_load_file("gallery.xml");
foreach ( $xml as $photo ) {
if ($photo['id'] == $file) {
$output .= !empty($photo->date) ? "<p>Date taken: {$photo->date}</p>" : '';
$output .= !empty($photo->locale) ? "<p>Location: {$photo->locale}</p>" : '';
$output .= !empty($photo->comment) ? "<p>Comment: {$photo->comment}</p>" : '';
}
}
return $output;
}
/**
* The simplified version included in the article
*/
function get_image_list ( $image_dir ) {
$d = dir($image_dir);
$files = array();
if ( !$d ) return null;
while (false !== ($file = $d->read())) {
// getimagesize returns true only on valid images
if ( @getimagesize( $image_dir . '/' . $file ) ) {
$files[] = $file;
}
}
$d->close();
return $files;
}
?>
上一篇:
36.1.index.php
下一篇:
天亮之后