[PHP] Image Gallery Script with thumbnails-VBForums
Results 1 to 2 of 2

Thread: [PHP] Image Gallery Script with thumbnails

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    [PHP] Image Gallery Script with thumbnails

    This is a little image gallery script with thumbnails that I wrote. All you do is place the index.php file in a folder with images and voila, you have a nice little image gallery.

    PHP Code:
    <?
    //************************************************************//
    //                                                            //
    //                PHP Slideshow v0.1                          //
    //                Author: Brian Mahler                        //
    //                Copyright (c) 2006 Brian Mahler             //
    //                                                            //          
    //************************************************************//
    //
    // CSS to position and change appearance
    // Modify these settings to change the appearance of the page
    //
    ?>
    <!doctype html public "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
       <head>
          <title>PHP Slideshow v0.1 by Brian Mahler</title>
            <style type="text/css">
                body{
                    background-color:#eee;
                }
                a:link, a:active, a:visited{
                    text-decoration:none;
                    color: #000;    
                }
                a:hover{
                    color: #bbb;    
                }
                table#images{ /* Includes PageNav,ImageNav and Image */
                    margin:auto;
                }
                td#copy{
                    font-family: times;
                    font-size:8pt;
                }
                Table#nav{ /* Navigation table */
                        
                }
                img#view{
                     
                }
                
            </style>
        </head>
        <body>
    <?
    //Definitions
    //
    //To change the number of thumbnails on a page, simply change the number  below
    //
    define("PER_PAGE",8);


    //---------------------------------------------Do not Edit below this line-----------------------------------------------

    //Get the path to the current directory
    $z split('/'$_SERVER['SCRIPT_FILENAME']);
    $thisname $z[count($z)-1];
    $path str_replace($thisname''$_SERVER['SCRIPT_FILENAME']);

    //Define allowed file extensions
    $allowed = array('jpg','gif','png');

    //Read through the directory and find all files with proper file extensions
    $dir dir($path);
    while (
    $file $dir->read()) {
        if ((
    $file != '.') && ($file != 'CVS') && ($file != '..')) {
            
    $file_size filesize($path $file);
            
    $file_extension file_ext($file);
            if(!
    is_dir($path $file) && isset($file_extension) && in_array($file_extension$allowed)) {
                
    $images[] = array('name' => $file,
                                  
    'size' => $file_size);
            }     
        }
    }

    //Check for images present in the directory
    $count count($images);
    if (
    $count 1){
        die(
    '<center>No images present in current directory</center>');
    }

    //Calculate the number of pages
    $pages ceil($count PER_PAGE);

    //Get the current page

    if (!isset($_GET['page'])){
        
    $current_page 1;
    }else{
        
    $current_page $_GET['page'];
    }

    //Page Navigation
    if ($current_page == 1) {
         
    $next $current_page 1;
        
    $pagehtml '<b>Page ' $current_page ' of ' $pages '</b> | <a class="navi" href="index.php?page=' $next '">Next Page &gt;</a>';
    }elseif (
    $current_page == $pages){
         
    $back $current_page 1;
        
    $pagehtml '<a class="navi" href="index.php?page=' $back '">&lt; Previous Page</a> | <b>Page '  $current_page ' of ' $pages '</b>';             
    }else{
        
    $next $current_page 1;
        
    $back $current_page 1;
         
    $pagehtml '<a class="navi" href="index.php?page=' $back '">&lt; Previous Page</a> | <b>Page '  $current_page ' of ' $pages '</b> | <a class="navi" href="index.php?page=' $next '">Next Page &gt;</a>';
    }


    //Build the thumbnail navigation table
    $y $current_page PER_PAGE;
    $start $y PER_PAGE 1;
    $image_nav '<table width="500px" id="nav"><tr>';
    for (
    $x=$start$x<=$y$x++){
         if (
    $x <= $count){
             
    $url $images[$x -1]['name'];
            
    $image_nav .= '<td align="center" valign="center" width="12.5%"><a href="index.php?page=' $current_page '&id=' $x '"><img src="' $url '" border="0" width="60px"></a></td>';
            
        }
    }
    $image_nav .= '</tr></table>';

    //The image to be shown
    $image_view $_GET['id'];
    if (!isset(
    $_GET['id'])){
        
    $image_view $current_page 7;
    }
    $image '<img id="view" src="' $images[$image_view 1]['name'] . '" width="512px">'

    $copy 'PHP Slideshow v0.1 &copy;2006 Brian Mahler';

    //Display the slideshow
    echo '<table id="images" width="500px" border="0" cellpadding="2px">';
    echo 
    '<tr><td align="center">' $pagehtml '</td></tr><tr><td align="center">' $image_nav '</td></tr><tr><td id="pic" align="center" valign="center" style="padding:2px;">' $image '</td></tr>';
    echo 
    '<tr><td id="copy" align="center">' $copy '</td></tr>';
    echo 
    '</table>';

    //function to get file extension of files
    function file_ext($file) {
        
    $extension split("[.]"$file);
        
    $ext_file $extension[count($extension)-1];
        return 
    strtolower($ext_file);
    }
    ?>
        </body>
    </html>
    Attached Files Attached Files
    Last edited by bmahler; Sep 27th, 2006 at 07:48 PM.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0 PHP Image Gallery v2.0
    VB 2005
    Find Computers on a network Simple License Encryption SQL Server Database Access dll Use Reflection to Return Crystal ReportDocument Silently Print PDF Generic Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost) MSDN Design Guidelines API Reference Inno Setup Compiler Inno Setup Preprocessor ISTool - Fairly easy to use GUI for creating inno setup projects Connection Strings NAnt -Automated Builds Cruise Control .NET - Frontend for automated builds

  2. #2
    New Member
    Join Date
    Jun 2012
    Location
    i live in Pakistan
    Posts
    1

    Re: [PHP] Image Gallery Script with thumbnails

    Nice thread... keep it upp...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.