SitePoint Sponsor

User Tag List

Page 14 of 31 FirstFirst ... 410111213141516171824 ... LastLast
Results 326 to 350 of 767
  1. #326
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I check the source for an image I see this...

    But when I check my photos dir there is nothing! When I check my database I can see the record for the file but it's not in the photos dir.

    Help Please!



    HTML Code:
    <html>
    <head>
    	<title>Gallery View</title>
    </head>
    <body>
    <table width='100%' border='0' align='center' style='width: 100%;'>
    <tr>
    	<td>
    						<a href='viewgallery.php'>Categories</a> &gt; 
    						<a href='viewgallery.php?cid=3'>Party</a></td>
    
    </tr>
    <tr>
    	<td align='center'>
    					<br />
    					<img src='photos/9.jpg' border='0' alt='Adam and Kim in Vegas for Halloween 2003.' />
    					<br />
    					Adam and Kim in Vegas for Halloween 2003.
    					</td>
    					</tr>		
    </table>
    </body>
    
    </html>
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  2. #327
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Did you check that the images exist on the server .. ?

    Maybe they didnt successfully upload ..

    Cheers

  3. #328
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked the "photos" dir on the server and they are not there. I checked my mysql database and the files are listed in the records as file 1-7 with captions. I don't think they did...... How do i fix this?

    Here is a screenshot of what I see after I upload files....



    and here is a screen shot of my online dir after upload



    Notice the "photos" dir is empty.

    Here is a screenshot of my photos table


    Thanks for all of your help!

    Todd
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  4. #329
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Have you got a folder on your server called photos assuming in your config file is like:

    $images_dir = "photos";

    .. and chmod it to 777?

    Altho if you havnt allready done that you may have got errors?

    Cheers

  5. #330
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The following code is used for my config file

    PHP Code:
    <?php

     $mysql_link 
    mysql_connect('db151.perfora.net''dbo118613358''*******');
     
    mysql_select_db('db118613358') or die('Could not select database');

     
    $images_dir 'photos';

    ?>
    What is my chmod and how do I set it to 777?

    Thanks for your help
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  6. #331
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it working!!!
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  7. #332
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I assume you ftp to your webserver?

    Create a folder called photos in the public_html ( where ever the home dir is )

    Right click the photos folder and click on "properties/CHOMD" set the permissions to "777" which is read/write/exicute for owner group and public .. click apply ..

    Try to upload more images and see how you go ..


    Cheers

  8. #333
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now comes the tough part..... I'd like to make a few changes and I'm not sure how I should go about doing it.

    1 - I would like to include "Albums" inside categories so each photo belongs to only one album and each album belongs in only one category.

    2 - I would like to include more info than "caption". I think all I need to do for that is add the fields to the form and add the records to the "gallery_photos" table.

    3 - I'd like to format the "full size" image pages so that they look something like this
    http://benrud.net/pics/lake/2004_lak...u/amanda.shtml

    4 - I'd like to format the "viewgallery.php" page and subsequent pages so that they appear inside my site design like this...
    http://benrud.net/pics/lake/2004_lak...rial_day.shtml

    Now I know these might be tall orders especially for a beginner like me so I'm open to suggestions regarding your help. I really need/want to get this gallery up and working soon.

    Please post any help you can offer or e-mail me at todd@benrud.net
    PLEASE HELP!!!!

    Thanks to all of you for your help!
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  9. #334
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I would consider recoding your site .. using theme and functions:

    Theme tutorial: http://www.phpfreaks.com/tutorials/8/0.php
    Function tutorial: http://www.phpfreaks.com/tutorials/1/0.php

    This will make your site more managable and also give a nice clean interface ..

    To edit the way the fullsize image & caption displays you will need to edit the html in the following peice of code found on the index.php page:

    PHP Code:
    // 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><font class=\"txt\">No Photo found</font></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>
                                                    <font class=\"txt\"><center><b><a href='index.php?pages=gallery'>Categories</a></b> - 
                                                    <a href='../index.php?pages=gallery&cid=
    $cid'><b>Thumbnail Listing</a></b><br><br>
                                                    
    $category_name</center></font></td>\n</tr>\n";

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

    // Final Output
    echo <<<__HTML_END
    <div align='center'><fieldset><legend><strong><span class='txt2'>PHOTO GALLERY</span></strong></legend><br>
    <table width='75%' cellspacing='0' cellpadding='5' border='0' bordercolor='' align='center'>
    $result_final                
    </table><br><br>
    </fieldset></div>
    __HTML_END;

    ?> 
    The answer to your questions is really learning the coding style being used in the gallery script .. and modify it to display to your preference. Most of which will be found in the index.php

    Good luck

    Cheers

  10. #335
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Matrix,

    Thanks for the links. I currently use .ssi files to maintain most of my site. However, once I become more experienced with php I plan on using i<?php include?> for header, footer and navigation. Is this what the tutorials were talking about? I haven't had time to read them yet.

    ONe more quick question.... I've set up my gallery_photos table up to include the items below but when I go to the preupload page and enter the information the only thing that is added to the table is file name and caption. Do you know why it's not adding, title, meta keywords, meta description, etc... and instead entering the value of "NULL"?



    Below is the code for preupload...

    PHP Code:
    <?php
     
    include 'config.inc.php';

     
    // initialization
     
    $photo_upload_fields '';
     
    $counter 1;

     
    // If we want more fields, then use, preupload.php?number_of_fields=20
     
    $number_of_fields = (isset($_GET['number_of_fields'])) ?
       (int)(
    $_GET['number_of_fields']) : 5;

     
    // Firstly Lets build the Category List
     
    $result mysql_query('SELECT category_id,category_name FROM gallery_category');
     while(
    $row mysql_fetch_array($result)) {
       
    $photo_category_list .= <<<__HTML_END
    <option value="$row[0]">$row[1]</option>\n
    __HTML_END;
     }
     
    mysql_free_result$result );  

     
    // Lets build the Image Uploading fields
     
    while($counter <= $number_of_fields) {
       
    $photo_upload_fields .= <<<__HTML_END
    <tr><td>
     Photo 
    {$counter}:
     <input name="photo_filename[]"
    type="file" />
    </td></tr>
    <tr><td>
     Caption:
     <textarea name="photo_caption[]" cols="30"
       rows="1"></textarea>
    </td></tr>
    <tr><td>
     Meta Key Words:
     <textarea name="photo_meta_key[]" cols="30"
       rows="1"></textarea>
    </td></tr>
    <tr><td>
     Meta Description:
     <textarea name="photo_meta_description[]" cols="30"
       rows="1"></textarea>
    </td></tr>
    <tr><td>
     Page Title:
     <textarea name="photo_title[]" cols="30"
       rows="1"></textarea>
    </td></tr>
    <tr><td>
     Featured Products:
     <textarea name="photo_products[]" cols="30"
       rows="1"></textarea>
       <hr>

    </td></tr>
    __HTML_END;
       
    $counter++;
     }

     
    // Final Output
     
    echo <<<__HTML_END
    <html>
    <head>
    <title>Lets upload Photos</title>
    </head>
    <body>
    <form enctype="multipart/form-data"
     action="upload.php" method="post"
     name="upload_form">
     <table width="90%" border="0"
       align="center" style="width: 90%;">
       <tr><td>
         Select Category
         <select name="category">
         
    $photo_category_list
         </select>
       </td></tr>
       <!—Insert the image fields here -->
       
    $photo_upload_fields
       <tr><td>
         <input type="submit" name="submit"
           value="Add Photos" />
       </td></tr>
     </table>
    </form>
    </body>
    </html>
    __HTML_END;
    ?>
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  11. #336
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Backup the file called "upload.php" and try replacing with the following code .. see how you get on ..

    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/bmp' => 'bmp',
    'image/x-png' => 'png');
            
    // GD Function Suffix List
    $gd_function_suffix = array(
    'image/pjpeg' => 'JPEG',
    'image/jpeg' => 'JPEG',
    'image/bmp' => 'WBMP',
    'image/x-png' => 'PNG');

    // Fetch the photo array sent by preupload.php
    $photos_uploaded $_FILES['photo_filename'];
    $photoFileName$_FILES['photo_filename'];
            
    // Fetch the photo caption array
    $photo_caption $_POST['photo_caption'];
    $photo_meta_key $_POST['photo_meta_key'];
    $photo_meta_description $_POST['photo_meta_description'];
    $photo_title $_POST['photo_title'];
    $photo_products $_POST['photo_products'];

    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`, `photo_meta_key`, `photo_meta_description`, `photo_title`, `photo_products`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."', '".addslashes($_POST['photo_meta_key'])."', '".addslashes($_POST['photo_meta_description'])."', '".addslashes($_POST['photo_title'])."', '".addslashes($_POST['photo_description'])."')" );
                                    
    $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);

    // Let's get the original image size
                                    
    $size GetImageSize$images_dir."/".$filename );

    // First Create Thumbnail!
    // Thumbnail Settings
            
    $Config_tbwidth_wide 80// width of wide image
            
    $Config_tbheight_wide 80// height of wide image

            
    $Config_tbwidth_tall 80// width of tall image
            
    $Config_tbheight_tall 80// height of tall image

    // The Code
            
    if($size[0] > $size[1]){
                
    $thumbnail_width $Config_tbwidth_wide;
                
    $thumbnail_height = (int)($Config_tbwidth_wide $size[1] / $size[0]);

                if(
    $thumbnail_height $Config_tbheight_wide){
                    
    $thumbnail_height $Config_tbheight_wide;
                    
    $thumbnail_width = (int)($Config_tbheight_wide $size[0] / $size[1]);
                }
            }else{
                
    $thumbnail_width = (int)($Config_tbheight_tall $size[0] / $size[1]);
                
    $thumbnail_height $Config_tbheight_tall;

                if(
    $thumbnail_width $Config_tbwidth_tall){
                    
    $thumbnail_width $Config_tbwidth_tall;
                    
    $thumbnail_height = (int)($Config_tbwidth_tall $size[1] / $size[0]);
                }
            }

    // Build Thumbnail with GD 2.x.x, you can use the other described methods too
    $function_suffix $gd_function_suffix[$filetype];
    $function_to_read "ImageCreateFrom".$function_suffix;
    $function_to_write "Image".$function_suffix;

    // Read the source file
    $source_handle $function_to_read $images_dir."/".$filename );

    if(
    $source_handle){
    // Let's create a blank image for the thumbnail
    $destination_handle ImageCreateTrueColor $thumbnail_width$thumbnail_height );

    // Now we resize it
    ImageCopyResampled$destination_handle$source_handle0000$thumbnail_width$thumbnail_height$size[0], $size[1] );
    }

    // Let's save the thumbnail
    $function_to_write$destination_handle$images_dir."/tb_".$filename100 );
    ImageDestroy($destination_handle );

    // .................................................................................
    // Lets resize the image if its width is greater than 500 pixels
    // Resized image settings
    if ($size[0] > '500'){
            
    $Config_width_wide 500// width of wide image
            
    $Config_height_wide 475// height of wide image

            
    $Config_width_tall 475// width of tall image
            
    $Config_height_tall 500// height of tall image

    // The Code
            
    if($size[0] > $size[1]){
                
    $image_width $Config_width_wide;
                
    $image_height = (int)($Config_width_wide $size[1] / $size[0]);

                if(
    $image_height $Config_height_wide){
                    
    $image_height $Config_height_wide;
                    
    $image_width = (int)($Config_height_wide $size[0] / $size[1]);
                }
            }else{
                
    $image_width = (int)($Config_height_tall $size[0] / $size[1]);
                
    $image_height $Config_height_tall;

                if(
    $image_width $Config_width_tall){
                    
    $image_width $Config_width_tall;
                    
    $image_height = (int)($Config_width_tall $size[1] / $size[0]);
                }
            }

    // Build image with GD 2.x.x, you can use the other described methods too
    $function_suffix $gd_function_suffix[$filetype];
    $function_to_read "ImageCreateFrom".$function_suffix;
    $function_to_write "Image".$function_suffix;

    // Read the source file
    $source_handle $function_to_read $images_dir."/".$filename );

    if(
    $source_handle){
    // Let's create a blank image for the image
    $destination_handle ImageCreateTrueColor $image_width$image_height );

    // Now we resize it
    ImageCopyResampled$destination_handle$source_handle0000$image_width$image_height$size[0], $size[1] );
    }

    // Let's save the image
    $function_to_write$destination_handle$images_dir."/".$filename90 );
    ImageDestroy($destination_handle );

    }

    $result_final .= "<font class=\"txt\"><img src='".$images_dir"/tb_".$filename."' /><br>File ".($counter+1)." Added Successfully!</font><br><br>";

    }
    }
    $counter++;
    }

    // Print Result
    echo <<<__HTML_END
    $design_header<br>
    $result_final<br>
    <font class="txt"><a href="../index.php?pages=adminindex">Back to Photogallery Admin Page</a></font<br>
    $design_footer
    __HTML_END;
    ?>
    You may want to edit the thumbnail and image properties to your preference as well ..


    Cheers

  12. #337
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Matrix,

    After I upload I get this error

    Parse error: parse error, unexpected $ in /homepages/4/d94933377/htdocs/photo_album/upload.php on line 168

    I don't know enough about php to figure this one out. Can u help?
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  13. #338
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Hmmz didnt really see anything out of place .. Try this:

    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/bmp' => 'bmp',
    'image/x-png' => 'png');
            
    // GD Function Suffix List
    $gd_function_suffix = array(
    'image/pjpeg' => 'JPEG',
    'image/jpeg' => 'JPEG',
    'image/bmp' => 'WBMP',
    'image/x-png' => 'PNG');

    // Fetch the photo array sent by preupload.php
    $photos_uploaded $_FILES['photo_filename'];
    $photoFileName$_FILES['photo_filename'];
            
    // Fetch the photo caption array
    $photo_caption $_POST['photo_caption'];
    $photo_meta_key $_POST['photo_meta_key'];
    $photo_meta_description $_POST['photo_meta_description']; 
    $photo_title $_POST['photo_title']; 
    $photo_products $_POST['photo_products']; 

    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`, `photo_meta_key`, `photo_meta_description`, `photo_title`, `photo_products`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."', '".addslashes($_POST['photo_meta_key'])."', '".addslashes($_POST['photo_meta_description'])."', '".addslashes($_POST['photo_title'])."', '".addslashes($_POST['photo_description'])."')" );
                                    
    $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);

    // Let's get the original image size
                                    
    $size GetImageSize$images_dir."/".$filename );

    // First Create Thumbnail!
    // Thumbnail Settings
            
    $Config_tbwidth_wide 80// width of wide image
            
    $Config_tbheight_wide 80// height of wide image

            
    $Config_tbwidth_tall 80// width of tall image
            
    $Config_tbheight_tall 80// height of tall image

    // The Code
            
    if($size[0] > $size[1]){
                
    $thumbnail_width $Config_tbwidth_wide;
                
    $thumbnail_height = (int)($Config_tbwidth_wide $size[1] / $size[0]);

                if(
    $thumbnail_height $Config_tbheight_wide){
                    
    $thumbnail_height $Config_tbheight_wide;
                    
    $thumbnail_width = (int)($Config_tbheight_wide $size[0] / $size[1]);
                }
            }else{
                
    $thumbnail_width = (int)($Config_tbheight_tall $size[0] / $size[1]);
                
    $thumbnail_height $Config_tbheight_tall;

                if(
    $thumbnail_width $Config_tbwidth_tall){
                    
    $thumbnail_width $Config_tbwidth_tall;
                    
    $thumbnail_height = (int)($Config_tbwidth_tall $size[1] / $size[0]);
                }
            }

    // Build Thumbnail with GD 2.x.x, you can use the other described methods too
    $function_suffix $gd_function_suffix[$filetype];
    $function_to_read "ImageCreateFrom".$function_suffix;
    $function_to_write "Image".$function_suffix;

    // Read the source file
    $source_handle $function_to_read $images_dir."/".$filename );

    if(
    $source_handle){
    // Let's create a blank image for the thumbnail
    $destination_handle ImageCreateTrueColor $thumbnail_width$thumbnail_height );

    // Now we resize it
    ImageCopyResampled$destination_handle$source_handle0000$thumbnail_width$thumbnail_height$size[0], $size[1] );
    }

    // Let's save the thumbnail
    $function_to_write$destination_handle$images_dir."/tb_".$filename100 );
    ImageDestroy($destination_handle );

    // .................................................................................
    // Lets resize the image if its width is greater than 500 pixels
    // Resized image settings
    if ($size[0] > '500'){
            
    $Config_width_wide 500// width of wide image
            
    $Config_height_wide 475// height of wide image

            
    $Config_width_tall 475// width of tall image
            
    $Config_height_tall 500// height of tall image

    // The Code
            
    if($size[0] > $size[1]){
                
    $image_width $Config_width_wide;
                
    $image_height = (int)($Config_width_wide $size[1] / $size[0]);

                if(
    $image_height $Config_height_wide){
                    
    $image_height $Config_height_wide;
                    
    $image_width = (int)($Config_height_wide $size[0] / $size[1]);
                }
            }else{
                
    $image_width = (int)($Config_height_tall $size[0] / $size[1]);
                
    $image_height $Config_height_tall;

                if(
    $image_width $Config_width_tall){
                    
    $image_width $Config_width_tall;
                    
    $image_height = (int)($Config_width_tall $size[1] / $size[0]);
                }
            }

    // Build image with GD 2.x.x, you can use the other described methods too
    $function_suffix $gd_function_suffix[$filetype];
    $function_to_read "ImageCreateFrom".$function_suffix;
    $function_to_write "Image".$function_suffix;

    // Read the source file
    $source_handle $function_to_read $images_dir."/".$filename );

    if(
    $source_handle){
    // Let's create a blank image for the image
    $destination_handle ImageCreateTrueColor $image_width$image_height );

    // Now we resize it
    ImageCopyResampled$destination_handle$source_handle0000$image_width$image_height$size[0], $size[1] );
    }

    // Let's save the image
    $function_to_write$destination_handle$images_dir."/".$filename90 );
    ImageDestroy($destination_handle );

    }

    $result_final .= "<font class=\"txt\"><img src='".$images_dir"/tb_".$filename."' /><br>File ".($counter+1)." Added Successfully!</font><br><br>";

    }
    }
    $counter++;
    }

    // Print Result
    echo <<<__HTML_END
    $design_header<br>
    $result_final<br>
    $design_footer
    __HTML_END;
    ?>

  14. #339
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    matrix,

    it still isn't working. It's not loading the files to the db and i'm still getting the error....

    Parse error: parse error, unexpected $ in /homepages/4/d94933377/htdocs/photo_album/upload.php on line 167
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  15. #340
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Matrix,

    I changed the //print results section from what u gave me to what I was using and now it uploads the photos but still doesn't put contents of the meta, title, products, etc... into the gallery_photos table. Instead it changes it to array.

    Do you know why the content from the text fields; mets, title, products, etc... are not being entered into the db like caption?

    your code...
    PHP Code:
    // Print Result
    echo <<<__HTML_END
    $design_header<br>
    $result_final<br>
    $design_footer
    __HTML_END;?> 
    what I have up there now...
    PHP Code:
        // Print Result
    echo <<<__HTML_END

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

    __HTML_END;
    ?> 
    Screenshot of table...
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  16. #341
    SitePoint Member
    Join Date
    Aug 2004
    Location
    boise
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great article, but... does anyone know of a way to change the code to produce a perfectly square thumbnail? For example find the longer side and cut off equal amounts on each side so the longer side ends up the same as the shorter size, thus a square thumb?

  17. #342
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey benrud,

    Sorry I was in a rush when I last posted upload.php .. wasnt really taking any notice of what I was doing ..

    Replace preupload.php and upload.php with the following codes .. Should work this time ..

    preupload.php:

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

            
    // initialization
            
    $photo_upload_fields "";
            
    $counter 1;

            
    // default number of fields
            
    $number_of_fields 5;

    // If you want more fields, then the call to this page should be like, 
    // preupload.php?number_of_fields=20

            
    if( $_POST['number_of_fields'] )
            
    $number_of_fields = (int)($_POST['number_of_fields']);

            
    // Firstly Lets build the Category List

            
    $result mysql_query"SELECT category_id,category_name FROM gallery_category" );
            while( 
    $row mysql_fetch_array$result ) )
            {
    $photo_category_list .=<<<__HTML_END
            <option value="$row[0]">$row[1]</option>\n
    __HTML_END;
            }
            
    mysql_free_result$result );        

    // Lets build the Photo Uploading fields
            
    while( $counter <= $number_of_fields )
            {
    $photo_upload_fields .=<<<__HTML_END
    <tr>
            <td>
                 Photo 
    {$counter}:
                <input name=' photo_filename[]' type='file' />
            </td>
    </tr>
    <tr>
            <td>
                 Caption:
                <textarea name='photo_caption[]' cols='30' rows='1'></textarea>
            </td>
    </tr>
    <td>
                 Photo Meta Key:
                <textarea name='photo_meta_key[]' cols='30' rows='1'></textarea>
            </td>
    </tr>
    <td>
                 Photo meta description:
                <textarea name='photo_meta_description[]' cols='30' rows='1'></textarea>
            </td>
    </tr>
    <td>
                 Photo Title:
                <textarea name='photo_title[]' cols='30' rows='1'></textarea>
            </td>
    </tr>
    <td>
                 Photo Products:
                <textarea name='photo_products[]' cols='30' rows='1'></textarea>
            </td>
    </tr>
    </tr>
    </tr>
    </tr>
    __HTML_END;
            
    $counter++;
            }

    // Final Output
    echo <<<__HTML_END
    <html>
    <head>
            <title>Lets upload Photos</title>
    </head>
    <body>
    <form enctype='multipart/form-data' action='upload.php' method='post' name='upload_form'>
    <table width='90%' border='0' align='center' style='width: 90%;'>
    <tr>
            <td>Select Category: <select name='category'>
    $photo_category_list</select></td>
    </tr>
    <tr>
            <td>
                    <p>&nbsp;</p>
            </td>
    </tr>

    <!-Insert the photo fields here -->
    $photo_upload_fields

    <tr>
            <td>
                    <input type='submit' name='submit' value='Add Photos' />
            </td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    __HTML_END;
    ?>

    upload.php:

    PHP Code:
    <?php
    include("config.inc.php");
    include(
    "design.inc.php");
    include(
    "security.inc.php");

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

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

    // Fetch the photo array sent by preupload.php
    $photos_uploaded $_FILES['photo_filename'];
    $photoFileName$_FILES['photo_filename'];
            
    // Fetch the photo caption array
    $photo_caption $_POST['photo_caption'];
    $photo_meta_key $_POST['photo_meta_key'];
    $photo_meta_description $_POST['photo_meta_description'];
    $photo_title $_POST['photo_title'];
    $photo_products $_POST['photo_products'];

    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_meta_key`, `photo_meta_description`, `photo_title`, `photo_products`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($photo_meta_key[$counter])."', '".addslashes($photo_meta_description[$counter])."', '".addslashes($photo_title[$counter])."', '".addslashes($photo_products[$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);

    // Let's get the original image size
                                    
    $size GetImageSize$images_dir."/".$filename );

    // First Create Thumbnail!
    // Thumbnail Settings
            
    $Config_tbwidth_wide 150// width of wide image
            
    $Config_tbheight_wide 125// height of wide image

            
    $Config_tbwidth_tall 125// width of tall image
            
    $Config_tbheight_tall 150// height of tall image

    // The Code
            
    if($size[0] > $size[1]){
                
    $thumbnail_width $Config_tbwidth_wide;
                
    $thumbnail_height = (int)($Config_tbwidth_wide $size[1] / $size[0]);

                if(
    $thumbnail_height $Config_tbheight_wide){
                    
    $thumbnail_height $Config_tbheight_wide;
                    
    $thumbnail_width = (int)($Config_tbheight_wide $size[0] / $size[1]);
                }
            }else{
                
    $thumbnail_width = (int)($Config_tbheight_tall $size[0] / $size[1]);
                
    $thumbnail_height $Config_tbheight_tall;

                if(
    $thumbnail_width $Config_tbwidth_tall){
                    
    $thumbnail_width $Config_tbwidth_tall;
                    
    $thumbnail_height = (int)($Config_tbwidth_tall $size[1] / $size[0]);
                }
            }

    // Build Thumbnail with GD 2.x.x, you can use the other described methods too
    $function_suffix $gd_function_suffix[$filetype];
    $function_to_read "ImageCreateFrom".$function_suffix;
    $function_to_write "Image".$function_suffix;

    // Read the source file
    $source_handle $function_to_read $images_dir."/".$filename );

    if(
    $source_handle){
    // Let's create a blank image for the thumbnail
    $destination_handle ImageCreateTrueColor $thumbnail_width$thumbnail_height );

    // Now we resize it
    ImageCopyResampled$destination_handle$source_handle0000$thumbnail_width$thumbnail_height$size[0], $size[1] );
    }

    // Let's save the thumbnail
    $function_to_write$destination_handle$images_dir."/tb_".$filename100 );
    ImageDestroy($destination_handle );

    // .................................................................................
    // Lets resize the image if its width is greater than 500 pixels
    // Resized image settings
    if ($size[0] > '500'){
            
    $Config_width_wide 500// width of wide image
            
    $Config_height_wide 475// height of wide image

            
    $Config_width_tall 475// width of tall image
            
    $Config_height_tall 500// height of tall image

    // The Code
            
    if($size[0] > $size[1]){
                
    $image_width $Config_width_wide;
                
    $image_height = (int)($Config_width_wide $size[1] / $size[0]);

                if(
    $image_height $Config_height_wide){
                    
    $image_height $Config_height_wide;
                    
    $image_width = (int)($Config_height_wide $size[0] / $size[1]);
                }
            }else{
                
    $image_width = (int)($Config_height_tall $size[0] / $size[1]);
                
    $image_height $Config_height_tall;

                if(
    $image_width $Config_width_tall){
                    
    $image_width $Config_width_tall;
                    
    $image_height = (int)($Config_width_tall $size[1] / $size[0]);
                }
            }

    // Build image with GD 2.x.x, you can use the other described methods too
    $function_suffix $gd_function_suffix[$filetype];
    $function_to_read "ImageCreateFrom".$function_suffix;
    $function_to_write "Image".$function_suffix;

    // Read the source file
    $source_handle $function_to_read $images_dir."/".$filename );

    if(
    $source_handle){
    // Let's create a blank image for the image
    $destination_handle ImageCreateTrueColor $image_width$image_height );

    // Now we resize it
    ImageCopyResampled$destination_handle$source_handle0000$image_width$image_height$size[0], $size[1] );
    }

    // Let's save the image
    $function_to_write$destination_handle$images_dir."/".$filename90 );
    ImageDestroy($destination_handle );

    }

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

    }
    }
    $counter++;
    }

    // Print Result
    echo <<<__HTML_END

    <html>
    <head>
            <title>Photos uploaded</title>
    </head>
    <body>
    $design_header<br>
    $result_final<br>
    <a href="adminindex.php">Back to Administration Page</a><br>
    <a href="logout.php">Logout of Administration Area</a><br>
    $design_footer
    </body>
    </html>

    __HTML_END;
    ?>


    Cheers

  18. #343
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Everything working.... but no images!!

    Get tutorial... it's saved me loads of time!

    I've got a fairly major problem though..... I can add details to the database, but my images refuse to upload!

    here's the script for upload.php:

    PHP Code:
    <?php session_start();

    $goback "/gallery.php";

    if(
    $_SESSION['loggedin'] != 1)
    {
    header("Location:$goback");
    exit;
    }
    ?>

    <?php
        
        
    include("connect.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');
        
        
    // GD Function List
        
    $gd_function_suffix = array( 'image/pjpeg' => 'JPEG','image/jpeg' => 'JPEG','image/gif' => 'GIF','image/bmp' => 'WBMP','image/x-png' => 'PNG');

        
    // 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 photos(`photo_name`, `photo_caption`, `photo_album`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['album'])."')" );
                    
    $new_id mysql_insert_id();
                    
    $filetype $photos_uploaded['type'][$counter];
                    
    $extention $known_photo_types[$filetype];
                    
    $filename $new_id "." $extention;

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

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

                    
    // Let's get the Thumbnail size
                    
    $size GetImageSize$images_dir."/".$filename );
                    if(
    $size[0] > $size[1])
                    {
                    
    $thumbnail_width 100;
                    
    $thumbnail_height = (int)(100 $size[1] / $size[0]);
                    }
                    else
                    {
                    
    $thumbnail_width = (int)(100 $size[0] / $size[1]);
                    
    $thumbnail_height 100;
                    }
                
            
    $function_suffix $gd_function_suffix[$filetype];
            
    $function_to_read 'ImageCreateFrom' $function_suffix;
            
    $function_to_write 'Image' $function_suffix;

            
    // Read the source file
            
    $source_handle $function_to_read($images_dir '/' $filename);
           
                if (
    $source_handle) {
                 
    // Let's create a blank image for the thumbnail
                 
    $destination_handle ImageCreateTrueColor($thumbnail_width$thumbnail_height);

                 
    // Now we resize it
                 
    ImageCopyResampled($destination_handle$source_handle0000$thumbnail_width$thumbnail_height$size[0], $size[1]);
                }

                
    // Let's save the thumbnail
                
    $function_to_write($destination_handle$images_dir '/tb_' $filename);

                    
    $result_final .= "<img src='".$images_dir"/tb_".$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;
    ?>
    the connect.php is like this:

    PHP Code:
    $conn mysql_connect('localhost''///////''///////');
      
    mysql_select_db('Astmoor'$conn) or die('Could not select database');

    $images_dir "/gallery/photos"
    The gallery is actually a file called /gallery/viewgallery.php, but is inclueded in /gallery.php

    can anybody see the problem??

    (p.s. this is a windows machine, running everything locally, so no chmod problems!)

  19. #344
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Is your "photo" folder within the gallery folder on your server?

    Have you set the "folder" properties to CHMOD 777 .. ?

    Also maybe move the "photo" directory into the /public_html directory on ya server ..

    Give those ago ..


    Cheers

  20. #345
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm running everything locally, so chmod isn't going to be a problem... I was wondering if it was some mistake in the actual coding of the file?

    can anybody else offfer any assistance?

  21. #346
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If anyone has the same problem as me (see above ^), don't forget if your running locally on your machine, you need a FULL path for the &images_dir varible, not what I did. That solved the problem I was having!

    e.g. D:/Apache/Gallery/Photos

    Thanks for the help though

  22. #347
    Martin B
    SitePoint Community Guest
    You cannot use
    if ( empty(cid) && empty(pid))
    and so on in viewgallery.php since
    epmty retrns true also if cid is 0.
    The first gallery has category index 0, so
    the first galery cannot be shown.
    You have to use !isset instead:
    if ( (!isset($cid)) && (!isset($pid))
    and so on for the rest of the if's,
    except when testing for $nr, where empty is ok.

  23. #348
    Martin B
    SitePoint Community Guest
    Ok... sorry, maybe "autoincrement" on the photo_id and category_id fields will help.

  24. #349
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Matrix,

    now I get an error on line 100

    Parse error: parse error, unexpected $ in /homepages/4/d94933377/htdocs/photo_album/preupload.php on line 100

    any ideas?
    Thanks for all of your help!!! I'm NEW to php/mysql - 2/05

    View my progress at www.benrud.net

  25. #350
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by benrud
    Matrix,

    now I get an error on line 100

    Parse error: parse error, unexpected $ in /homepages/4/d94933377/htdocs/photo_album/preupload.php on line 100

    any ideas?
    Try removing the whitespaces after __HTML_END

    Line 100 appears to be the last line. put the ?> on it's own line.
    We have seen these problems in the past here.


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
  •