To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-22-2003, 10:05 PM   #1
MaxD
Pretty Humble Programmer
 
Join Date: Jun 2003
Location: New England, USA
Posts: 70
Image Gallery

This is my first real script. I'd just like to say, that I couldn't have done this if it weren't for PHP Builder's forums, and everyone who has helped me. Thanks everyone!

Here goes, I've tried to squish it down to fit the edges of the browser without messing up the code, but it's still a little wide. Bear with me?

thanks again!

PHP Code:
<?php
//********************************************//
// Get the stuff thats passed to the script and fix the case.
//

$class = strtolower($_GET['c']);
$do = strtolower($_GET['do']);
$id = strtolower($_GET['id']);

//********************************************//
// Define the stuff that gets passed to the header and footer.
// Include the dynamic stuff that comes from the _GETs
//

$bgVersion = "01";
$pageTitle = "Max Dodge [" . ucfirst($class) . " Gallery]";
$sig       = "gallery";
$pathToMain= "../";
$bannerOn  = "no";

if(
$do != "display"){
  
$locale    = ucfirst($class) . " Gallery";
  
$listToHere= " > <a href=\"index.php\">Gallery Selection</a>";
} else {
  
$locale    = "Display";
  
$listToHere= " > <a href=\"index.php\">Gallery Selection</a> >
<a href=
\"gallery.php?c=$class\">" . ucfirst($class) . " Gallery</a>";
}

//*******************************************//
// This is the function that reads the flat index file gal_idx.php, extrapolates the data
// and displays the thumbnails three across.
//
function thumb($c){

  
$count = 0;
  
$output_line = "";

  
$gallery_index = file("gal_idx.php");

  foreach(
$gallery_index as $gallery_index_line){        // This block of code nearly killed me.
    
if(!eregi("<\?",$gallery_index_line)){
      
$gallery_index = explode("|",$gallery_index_line);
      if((
strcasecmp($gallery_index[1], $c) == 0)){
        if(
$count == 3){
          
$output_line = $output_line . "            </tr>\n            <tr>\n";
          
$count = 0;
        }
        
$output_line = $output_line . "              <td class=thumb>"
. "<a href=\"$php_self?c=$c&do=display&id=$gallery_index[0]\">"
."<img src=\"$gallery_index[1]/t_$gallery_index[2].jpg\" alt=\"$gallery_index[3]\" border=\"0\" height=\"150\" width=\"100\">"
."</a></td>\n";
        
$count = $count + 1;
      }
    }
  }
  echo
"          <table border=\"0\" cellpadding=\"0\" cellspacing=\"10\" align=\"center\">\n"
."          <tr>\n" . $output_line
. "          </tr>\n          </table>\n";
}
//*******************************************//
// This is the really cool function that pulls out the picture according to it's ID.
// Unfortuatly, the ID is just the date that the picture was added... so you can have duplicate pics...
// I'll fix this later.
//
function display($eyedee){

  
$gallery_index = file("gal_idx.php");

  foreach(
$gallery_index as $gallery_index_line){
    if(!
eregi("<\?",$gallery_index_line)){
      
$gallery_index = explode("|",$gallery_index_line);
      if((
strcasecmp($gallery_index[0], $eyedee) == 0)){
        
$date = date("m/d/Y",strtotime($gallery_index[0]));
        echo
"<img src=\"$gallery_index[1]/$gallery_index[2].jpg\" alt=\"$gallery_index[3]\" border=\"0\" class=pic><br><br>\n"
           
."<table cellpadding=3 cellspacing=1 width=\"100%\" bgcolor=\"#565656\">"
           
."<tr bgcolor=\"#363636\"><td><b><font size=-2>Title: \"<i>$gallery_index[3]</i>\"</font></b></td>"
."<td bgcolor=\"#464646\"><div align=\"right\"><font size=-2>added: $date</font></div></td></tr>"
           
."<tr bgcolor=\"#262626\"><td colspan=2><font size=-2>$gallery_index[4]</font></td></tr></table>";
      }
    }
  }
}

//*****************************************//
// The header file
//
include($pathToMain . 'includes/header.inc');

//****************************************//
// Thumbs are default. No matter what. y'hear?
//
if ($do != "display"){        // "bangsign", hehee, I like that word
  
thumb($class);
}

//***************************************************************************************//
// If the do be to shaw den we be shawin' da pictcha yo
//
if ($do == "display"){
  
display($id);            // excuse me, I'll have to see ID for that
}

include(
$pathToMain . 'includes/footer.inc');

?>
this script uses an index file named "gal_idx.php" that looks a little like this"

PHP Code:
<?php
die()
/* [0]:id [1]:class [2]:photo [3]:title [4]:description */
?>
20030124|photo|artifact|The Artifact|Taken in West Jonesport, Maine
20030125|photo|chains|Chains|Taken in West Jonesport, Maine
20030126|photo|cosswaysunset|Cossway Sunset|Taken on Great Wass Island, Maine
the workin version is located at:
http://max.lundyarts.com/gallery/
(only the photos are added to the index file)
__________________
Open Source makes Strong Software
MaxD is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 10:10 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.