SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help required changing 'PHP Build An Automated PHP Gallery System In Minutes'

    Hi, recently found this tutorial 'PHP Build An Automated PHP Gallery System In Minutes'
    on this site and do with some help making some changes.

    I don't need the image resize/thumbnail generation because the images are already at
    the required size. I just need to be able to insert the images in different tables
    (London, Paris, Rome etc.), and when an image is clicked on, navigate to a page with more
    details about the location and the image. I am also hoping to be able to search the
    database and display the results in a gallery.

    I have removed the resize and thumbnails from the upload.php, and the thumbnails view from
    the viewgallery.php. When I try to view the viewgallery.php all I get is a blank page.
    I did get a blank page before I removed the un wanted parts. The tutorial has the following:

    'The value for the category id via the input variable cid is required for
    this screen to appear, e.g. viewgallery.php?cid=1'

    I assume this may have something to do with it but my knowledge of PHP is very basic and
    although I have been able to make changes, I don't fully understand what is going on - just
    lots of trial and error. Could someone please give me some pointers, I would like to display
    the original images on the page with links.

    Thanks in advance,
    Terrence

    I assume it is ok to include the PHP I am using.

    //upload.php
    PHP Code:
    <?php
        
    include("config.inc.php");

        
    // initialization
        
    $result_final "";
        
    $counter 0;

        
    // List of our known photo types
        
    $known_photo_types = array( 
                            
    'image/pjpeg' => 'jpg',
                            
    'image/jpeg' => 'jpg',
                            
    'image/gif' => 'gif',
                            
    'image/bmp' => 'bmp',
                            
    'image/x-png' => 'png'
                       
    &nbsp;
        
        
    // GD Function List
        
    $gd_function_suffix = array( 
                            
    'image/pjpeg' => 'JPEG',
                            
    'image/jpeg' => 'JPEG',
                            
    'image/gif' => 'GIF',
                            
    'image/bmp' => 'WBMP',
                            
    'image/x-png' => 'PNG'
                       
    &nbsp;

        
    // Fetch the photo array sent by preupload.php
        
    $photos_uploaded $_FILES['photo_filename'];

        
    // Fetch the photo caption array
        
    $photo_caption $_POST['photo_caption'];

        while( 
    $counter <= count($photos_uploaded) )
        {
            if(
    $photos_uploaded['size'][$counter] > 0)
            {
                if(!
    array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
                {
                    
    $result_final .= "File ".($counter+1)." is not a photo<br />";
                }
                else
                {
                    
    mysql_query"INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
                    
    $new_id mysql_insert_id();
                    
    $filetype $photos_uploaded['type'][$counter];
                    
    $extention $known_photo_types[$filetype];
                    
    $filename $new_id.".".$extention;

                    
    mysql_query"UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

                    
    // Store the orignal file
                    
    copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);

                    

                    
    $result_final .= "<img src='".$images_dir."/".$filename."' /> File ".($counter+1)." Added<br />";
                }
            }
        
    $counter++;
        }

        
    // Print Result
    echo <<<__HTML_END

    <html>
    <head>
        <title>Photos uploaded</title>
    </head>
    <body>
        
    $result_final
    </body>
    </html>

    __HTML_END;
    ?>
    //-----------------------------------------------------------
    //viewgallery.php
    PHP Code:
    <?php
        
    include("config.inc.php");

        
    // initialization
        
    $result_array = array();
        
    $counter 0;

        
    $cid = (int)($_GET['cid']);
        
    $pid = (int)($_GET['pid']);

        
    // Category Listing

        
    if( empty($cid) && empty($pid) )
        {
            
    $number_of_categories_in_row 4;

            
    $result mysql_query"SELECT c.category_id,c.category_name,COUNT(photo_id)
                            FROM gallery_category as c
                            LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                            GROUP BY c.category_id" 
    );
            while( 
    $row mysql_fetch_array$result ) )
            {
                
    $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
            }
            
    mysql_free_result$result );    

            
    $result_final "<tr>\n";

            foreach(
    $result_array as $category_link)
            {
                if(
    $counter == $number_of_categories_in_row)
                {    
                    
    $counter 1;
                    
    $result_final .= "\n</tr>\n<tr>\n";
                }
                else
                
    $counter++;

                
    $result_final .= "\t<td>".$category_link."</td>\n";
            }

            if(
    $counter)
            {
                if(
    $number_of_categories_in_row-$counter)
                
    $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\n";
                
    $result_final .= "</tr>";
            }
        }


        
    // Full Size View of Photo
        
    else if( $pid )
        {
            
    $result mysql_query"SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
            list(
    $photo_caption$photo_filename) = mysql_fetch_array$result );
            
    $nr mysql_num_rows$result );
            
    mysql_free_result$result );    

            if( empty( 
    $nr ) )
            {
                
    $result_final "\t<tr><td>No Photo found</td></tr>\n";
            }
            else
            {
                
    $result mysql_query"SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
                list(
    $category_name) = mysql_fetch_array$result );
                
    mysql_free_result$result );    

                
    $result_final .= "<tr>\n\t<td>
                            <a href='viewgallery.php'>Categories</a> &gt; 
                            <a href='viewgallery.php?cid=
    $cid'>$category_name</a></td>\n</tr>\n";

                
    $result_final .= "<tr>\n\t<td align='center'>
                        <br />
                        <img src='"
    .$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' />
                        <br />
                        
    $photo_caption
                        </td>
                        </tr>"
    ;
            }
        }

    // Final Output
    echo <<<__HTML_END

    <html>
    <head>
        <title>Gallery View</title>
    </head>
    <body>
    <table width='100%' border='0' align='center' style='width: 100%;'>
    <p>Boo Hoo</p>
    $result_final        
    </table>
    </body>
    </html>

    __HTML_END;
    ?>
    Last edited by spikeZ; Jan 5, 2012 at 03:21. Reason: added tags

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    The tutorial you're following gives you several pieces that are part of every gallery script (upload pictures and show the pictures of a certain category).

    It is not a complete script though.
    The value for the category id via the input variable cid is required for
    this screen to appear, e.g. viewgallery.php?cid=1
    This means that when you call the viewgallery script, you need to tell it what category to show. Of course, you can't expect visitors of your site to know the category id's, so what you need is another page with links to all categories. Clicking on a category link will then call the viewgallery script with the correct category id.

    To test your viewgallery script, you can write 'viewgallery.php?cid=1' in your browser to show the pictures of category 1. To check the category id's present in your database you could view the table data using phpMyAdmin.
    It's also a good idea to test your queries in phpMyAdmin.


Bookmarks

Posting Permissions

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