irwan

PHP Image Gallery

Nov 15th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.25 KB | None | 0 0
  1. <?
  2. //************************************************************//
  3. //                                                            //
  4. //                PHP Image Gallery v2.0                          //
  5. //                Author: Brian Mahler                        //
  6. //                Copyright (c) 2006 Brian Mahler             //
  7. //                                                            //
  8. //  This script is free to use and modify to your needs as    //
  9. //  long as this copyright notice remains in tact.            //
  10. //                                                            //        
  11. //************************************************************//
  12. //
  13. // CSS to position and change appearance
  14. // Modify these settings to change the appearance of the page
  15. //
  16. ?>
  17. <!doctype html public "-//W3C//DTD HTML 4.01//EN"
  18.    "http://www.w3.org/TR/html4/strict.dtd">
  19. <html>
  20.    <head>
  21.       <title>PHP Slideshow v2.0 by Brian Mahler</title>
  22.         <style type="text/css">
  23.             body{
  24.                 background-color:#eee;
  25.                 text-align:center;
  26.             }
  27.             a:link, a:active, a:visited{
  28.                 text-decoration:none;
  29.                 color: #000;  
  30.             }
  31.             a:hover{
  32.                 color: #bbb;  
  33.             }
  34.             table#images{ /* Includes PageNav,ImageNav and Image */
  35.                 margin:auto;
  36.             }
  37.             td#copy{
  38.                 font-family: times;
  39.                 font-size:8pt;
  40.             }
  41.             Table#nav{ /* Navigation table */
  42.  
  43.             }
  44.             img#view{
  45.                  
  46.             }
  47.             img.navpic{
  48.                 cursor:pointer;
  49.             }
  50.            
  51.         </style>
  52. <?
  53. //
  54. // Configuration Settings
  55. //
  56. define('IMAGE_WIDTH',480); //Width of image in pixels
  57. define('THUMBNAIL_SIZE',60); //Width of thumbnails in pixels
  58. define('THUMB_MAX_HEIGHT',360); //Max height of the thumbnails window in pixels
  59. define('THUMB_COLS',4); //Sets the number of Columns to use in the thumbnails
  60.  
  61. //---------------------------------------------Do not Edit below this line----------------------------------------------
  62. //                                          Unless you have knowledge of PHP
  63.  
  64. //Get the path to the current directory
  65. $z = split('/', $_SERVER['SCRIPT_FILENAME']);
  66. $thisname = $z[count($z)-1];
  67. if (!isset($_GET['path'])){
  68.     $path = str_replace($thisname, '', $_SERVER['SCRIPT_FILENAME']);
  69. }else{
  70.     $path = "./" . $_GET['path'];
  71. }
  72.  
  73. //Define allowed file extensions
  74. $allowed = array('jpg','gif','png');
  75.  
  76. //Read through the directory and find all files with proper file extensions
  77. $dir = dir($path);
  78. while ($file = $dir->read()) {
  79.     if (($file != '.') && ($file != 'CVS') && ($file != '..')) {
  80.         $file_size = filesize($path . $file);
  81.         $file_extension = file_ext($file);
  82.         if(!is_dir($path . $file) && isset($file_extension) && in_array($file_extension, $allowed)) {
  83.             $images[] = array('name' => $file,
  84.                               'size' => $file_size);
  85.         }    
  86.     }
  87. }
  88. ?>
  89. <script type="text/javascript">
  90. //The array to hold all the images
  91. var photos = new Array();
  92. //Preload images function
  93. function loadimages(){
  94. <?
  95. $count = count($images);
  96. for($i=1;$i<=$count;$i++){
  97.     echo 'photos[' . $i . ']= new Image()' . "\n";
  98.     echo 'photos[' . $i . '].src="' . $images[$i-1]['name'] . '"' . "\n";
  99. }
  100. ?>
  101. }
  102. //Javascript to display the images
  103. function showit(step){
  104.     document.images.view.src=photos[step].src
  105. }
  106.  
  107. window.onload = loadimages();
  108. </script>
  109. <?
  110.  
  111. //Check for images present in the directory
  112. if ($count < 1){
  113.     die('<center>No images present in current directory</center>');
  114. }
  115. //Create the image navigation table
  116. $image_nav = '<div style="overflow:auto;max-height:' . THUMB_MAX_HEIGHT . 'px;"><table id="nav"><tr>';
  117. for ($x=1; $x<=$count; $x++){
  118.      if ($x <= $count){
  119.          $url = $images[$x -1]['name'];
  120.          $image_nav .= '<td align="center" valign="center">';
  121.          if ($x%THUMB_COLS==0){
  122.             $image_nav .= '<a onclick="showit(' . $x . ')"><img class="navpic" src="' . $url . '" alt="' . $x . '" border="0" width="' . THUMBNAIL_SIZE . 'px" /></a></td></tr><tr>'    ;
  123.         }else{
  124.             $image_nav .= '<a onclick="showit(' . $x . ')"><img class="navpic" src="' . $url . '" alt="' . $x . '" border="0" width="' . THUMBNAIL_SIZE . 'px" /></a></td>';
  125.         }  
  126.     }
  127. }
  128. $image_nav .= '</tr></table></div>';
  129.  
  130.  
  131. //The image to be shown
  132. $image = '<img id="view" src="' . $images[0]['name'] . '" width="' . IMAGE_WIDTH . '">';
  133. //This script is free to use and modify to your needs, I just ask that you do not remove this copyright notice
  134. $copy = 'PHP Slideshow v2 ©2006 Brian Mahler';
  135.  
  136. //Display all elements
  137. ?>
  138. <table id="images" border="0" cellpadding="2px">
  139.     <tr><td align="left" valign="top"> <? echo $image_nav; ?></td><td id="pic" align="left" valign="top" style="padding:2px;"><? echo  $image; ?></td></tr>
  140.     <tr><td colspan="2" id="copy" align="center"><? echo $copy; ?></td></tr>
  141. </table>
  142.  
  143. <?
  144. //function to get file extension of files
  145. function file_ext($file) {
  146.     $extension = split("[.]", $file);
  147.     $ext_file = $extension[count($extension)-1];
  148.     return strtolower($ext_file);
  149. }
  150. ?>
  151.     </body>
  152. </html>
Advertisement
Add Comment
Please, Sign In to add comment