Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by aa ( 15 years ago )
// gallery.php

<?PHP

require('gallery.includes.php');

$folder = (!empty($_GET['folder'])) ? $_GET['folder'] : $album_dir;
if (!file_exists($folder)) $folder = $album_dir;

function get_album_thumb($album) {
 global $thumb_name;
 $handle = opendir($album);
 $pictures = Array();
 while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && substr($file, 0, 6) == $thumb_name) $pictures[] .= $file; }
 if (count($pictures) > 0) return '<img src="' . $album . '/' . $pictures[rand(0, (count($pictures)-1))] . '" />'; 
 else return '<img src="slike/slike_album.png" />';
 closedir($handle);
}
function get_albums($folder) {
 $handle = opendir($folder);
 while (false !== ($file = readdir($handle))) {
  if ($file != '.' && $file != '..') { 
   $xfile = explode('.', $file);
   if (count($xfile) == 1) { 
    $file = $folder . '/' . $file;
    echo '<a href="gallery.php?folder=' . $file . '"><div class="album">' . get_album_thumb($file) . '</div></a>';
   }
  }
 }
 closedir($handle);
}

function get_pics($folder) {
 global $thumb_name, $thumb_width, $thumb_height;
 $handle = opendir($folder);
 while (false !== ($file = readdir($handle))) {
  if ($file != '.' && $file != '..') { 
   $xfile = explode('.', $file);
   if ((count($xfile) > 1) && (in_var(strtolower($xfile[count($xfile)-1]), 'jpg jpeg png gif', ' ') == 1) && substr($file, 0, 6) == $thumb_name) {
    $image_path = $folder . '/' . $file;
    list($width, $height) = getimagesize($image_path);
    if ($width > $thumb_width) {
     resize_image($thumb_width, $thumb_height, $width, $height, $image_path);
    }
    echo '<div class="picture">
     <a href="preview.php?album=' . $folder . '&picture;=' . str_replace(substr($file, 0, 6), '', $file) . '">
     <img src="' . $folder . '/' . $file . '" />
     </a>
    </div>';
   }
  }
 }
 closedir($handle);
}



echo '
<style>
div.album {
 width: 175px;
 height: 134px;
 float: left;
 border: 1px solid #CCC;
 margin: 2px;
}
div.picture {
 width: 165px;
 float: left;
}
</style>
';

function gallery($folder) {
 echo '<div style="text-align: center; height: 500px; border: 1px solid black; padding: 10px; width: 910px">
  <div style="float: left; width: 100%">';
   get_albums($folder);
  echo '</div>
 <div style="width: 100%">';
   get_pics($folder);
 echo '</div>
 </div>';
}

gallery($folder);

?>

// gallery.includes.php

<?PHP

$thumb_width = '165';
$thumb_height = '124';
$image_width = '800';
$image_height = '600';
$thumb_name = 'thumb_';
$album_dir = 'album';

function in_var($var, $search, $sep) {
 $result = 0;
 $search = explode($sep, $search);
 for ($i = 0; $i <= (count($search)-1); $i++) if ($search[$i] == $var) $result = 1;
 return $result;
}

function resize_image($new_width, $new_height, $old_width, $old_height, $image_name) {
 $image_namex = explode('.', $image_name);
 if (in_var(strtolower($image_namex[count($image_namex)-1]), 'jpg jpeg', ' ') == 1) $image = imagecreatefromjpeg($image_name);
 if (strtolower($image_namex[count($image_namex)-1]) == 'png') $image = imagecreatefrompng($image_name);
 if (strtolower($image_namex[count($image_namex)-1]) == 'gif') $image = imagecreatefromgif($image_name);
 $image_ratio = ($new_width/$new_height);
 if ($image_ratio > 1) $new_height = ($new_width/$image_ratio);
 else $new_height = ($new_width*$image_ratio);
 $resampled = imagecreatetruecolor($new_width, $new_height);
 imagecopyresampled($resampled, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
 imagejpeg($resampled, $image_name, 100);
 imagedestroy($resampled);
 imagedestroy($image);
}

?>

// preview.php

<?PHP

require('gallery.includes.php');

$album = (!empty($_GET['album'])) ? $_GET['album'] : $album_dir;
$picture = (!empty($_GET['picture'])) ? $_GET['picture'] : '';

if (($album) && ($picture)) {
 $picture_preview = '';
 $picture_next = '';
 $image_path = $album . '/' . $picture;
 list($width, $height) = getimagesize($image_path);
 if ($width > $image_width) {
  resize_image($image_width, $image_height, $width, $height, $image_path);
 }
 $handle = opendir($album);
 $pictures = Array();
 while (false !== ($file = readdir($handle))) {
  $xfile = explode('.', $file);
  if (($file != '.') && ($file != '..') && (substr($file, 0, 6) != $thumb_name) 
   && (in_var(strtolower($xfile[count($xfile)-1]), 'jpg jpeg png gif', ' ') == 1)) $pictures[] .= $file;
 }
 for ($i = 0; $i <= (count($pictures)-1); $i++) {
  if ($picture == $pictures[$i]) {
   if (count($pictures) >= 2 && $i >= 1) $picture_preview = $pictures[$i-1];
   if ($i < (count($pictures)-1)) $picture_next = $pictures[$i+1];
  }
 }
 echo '<div style="text-align: center; height: 500px; border: 1px solid black; padding: 10px; width: 910px">';
 if ($picture_preview) echo '<a href="preview.php?album=' . $album . '&picture;=' . $picture_preview . '">Preview</a>';
 echo '<img src="' . $album . '/' . $picture . '" />';
 if ($picture_next) echo '<a href="preview.php?album=' . $album . '&picture;=' . $picture_next . '">Next</a>';
 echo '</div>';
}
else header('location: gallery.php');

?>

 

Revise this Paste

Children: 34833
Your Name: Code Language: