SitePoint Sponsor

User Tag List

Page 9 of 31 FirstFirst ... 567891011121319 ... LastLast
Results 201 to 225 of 767
  1. #201
    SitePoint Enthusiast mayank's Avatar
    Join Date
    Jul 2003
    Location
    India
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    replace current code:

    PHP Code:
        $cid = (int)($_GET['cid']);
        
    $pid = (int)($_GET['pid']); 
    to:

    PHP Code:
        $cid = isset($_GET['cid']) ? (int)($_GET['cid']) : 0;
        
    $pid = isset($_GET['pid']) ? (int)($_GET['pid']) : 0
    its possible ...

    < S-Point Articles :: Albinator :: mgZhome :: Beyond illusions />

  2. #202
    SitePoint Member nickthibert's Avatar
    Join Date
    May 2004
    Location
    Ottawa
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question very impressed... now, can we do this?

    here is the code that i have for the gallery damin section:

    PHP Code:
    <?PHP
    require_once('/Connections/goofy.php');
    if (
    $_SESSION['loggedIn'] != 'true') {
       
    //redirect the user to the login page
       
       
    echo "<h1> Access Denied </h1>";
       echo 
    "<p>Your user ID or password is incorrect, or you are not a registered user on this site.</p>";
       
       exit;
    }
    else {
        include(
    "config.inc.php"); 
    // the functions here 
    function edit_category($category_id$new_name

    mysql_query(
       UPDATE gallery_category SET 
         category_name = '" 
    addslashes($new_name) . "' 
       WHERE category_id = '" 
    addslashes($category_id) . "'"); 

    function 
    add_category($category_name

    mysql_query(
       INSERT INTO gallery_category ( 
        category_name 
       ) VALUES ( 
         '" 
    addslashes($category_name) . "' 
       )"
    ); 

    function 
    delete_category($category_id

    global 
    $images_dir
    $result mysql_query(
       SELECT photo_filename 
       FROM gallery_photo 
       WHERE photo_category='" 
    addslashes($category_id) . "'");    
    while (
    $row = @mysql_fetch_array($result)) { 
       
    unlink($images_dir '/' $row[0]); 

    mysql_query(
       DELETE FROM gallery_photo 
       WHERE photo_category='" 
    addslashes($category_id) . "'"); 
    mysql_query(
       DELETE FROM gallery_category 
       WHERE category_id='" 
    addslashes($category_id) . "'"); 

        if( empty(
    $_POST['action']) ) 
        { 
        
    // Firstly Lets build the Category List 
        
    $result mysql_query"SELECT category_id,category_name FROM gallery_category" ); 
        while( 
    $row mysql_fetch_array$result ) ) 
        { 
    $category_list .=<<<END
        <option value="$row[0]">$row[1]</option>\n 
    END;
        } 
        
    mysql_free_result$result );     
        
    $category_list '<select name="categoryid">'.$category_list.'</select>'
    ?> 
    <center><font face="Century Gothic">
    <form name="add_category" action="admin.php" method="post"> 
    <b>Add Category:</b><br /> 
    Name: <input type="text" name="cname" /> 
    <input type="submit" value="add" name="action" /> 
    </form> 

    <form name="edit_category" action="admin.php" method="post"> 
    <b>Edit Category:</b><br /> 
    New Name: <input type="text" name="cname" /> 
    <?php echo($category_list); ?> 
    <input type="submit" value="edit" name="action" /> 
    </form> 
     
    <form name="delete_category" action="admin.php" method="post"> 
    <b>Delete Category:</b><br /> 
    <?php echo($category_list); ?> 
    <input type="submit" value="delete" name="action" /> 
    </form> 
    </font></center>
    <?php 
        

        else 
        { 
            if( 
    strcasecmp($_POST['action'], "add")==&& !empty( $_POST['cname'] ) ) 
            { 
                
    add_category($_POST['cname']); 
            } 
            else if( 
    strcasecmp($_POST['action'], "edit")==&& !empty( $_POST['cname'] ) && !empty( $_POST['categoryid'] ) ) 
            { 
                
    edit_category($_POST['categoryid'], $_POST['cname']); 
            } 
            else if( 
    strcasecmp($_POST['action'], "delete")==&& !empty( $_POST['categoryid'] ) ) 
            { 
                
    delete_category($_POST['categoryid']); 
            } 
            else 
            { 
                echo(
    "Action not understood"); exit; 
            } 
            echo(
    "Process completed!"); 
        } 

    exit;
    }
    ?>
    here is the way i have my database setup:


    Field | Type | Null | Key | Default | Extra |

    category_id | bigint(20) unsigned | | PRI | NULL | auto_increment |
    category_name | varchar(50) | | | 0 | |
    public | set('yes','no') | | | no | |


    is there a way in the php code to allow the user to specify whether the gallery can be listed as a public gallery? i would need to setup it up like a drop-down menu (like the category list) and have it save that back to the database as either yes or no.... any help would be great

  3. #203
    SitePoint Member
    Join Date
    Jun 2004
    Location
    san gabriel
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am new to this whole PHP thing but I was able to get the gallery up and running.

    Now I would like to know a little about subcategory on the page.

    I have been able to make a new sub-category table tb_series with two columns series_name and series_id. I have been able to redo the preupload and upload page so that I can upload a image to the gallery_photos with a new column named series_id_category similar to having the link to the gallery_category.

    I would like to, on the "Screen 3. The full size Image", be able to show the series_name as text underneath the image and image_caption. Can someone show me how this is done, or can someone point me in the right direction on where I am suppose to do something on the viewgallery.php page?

    Thanks.

  4. #204
    SitePoint Member
    Join Date
    Jun 2004
    Location
    san gabriel
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still can't figure it out... anyone? at least a pointer in the right direction?

  5. #205
    SitePoint Enthusiast drewf's Avatar
    Join Date
    Mar 2002
    Location
    Calgary, AB
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking Resize of images to set width :: SOLVED! :)

    Ok Animal777 et all , I have spent a while learning how to solve the problem of getting my LARGE image files that excede my desired width (in this case 500 px wide) to be resized when uploaded. I have succeeded in my endevours and have included the code here for others to use.

    The file we are interested in is called upload.php and is the workhorse of the application anyhow. Essentially what I did was reuse the thumbnail code a second time, changing variables as needed to reflect a difference from the first set of code. My changes are highlighted in the code. I am not saying that I have coded everything very well mind you but it sure does solve the problem...

    If you can find a better way to do it please post your code to this thread.

    I don't have the time to 'support' this code as such so use it at your own will.

    Hopefully others will rekindle this thread and maybe we can all post our code and get this sucker to a really good level of completion and functionality. I do have a secure version of this gallery too with minor enhancements (like a form field that asks you how many pics. you want uploaded and then creates that many upload fields) and in the near future I will post it here in a zip file as an attachment.

    Anyhow enough about my ramblings...the code is here:

    PHP Code:
    <?php
            
    include("config.inc.php");
            include(
    "design.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'];
            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);
    // Let's get the original image size
                                    
    $size GetImageSize$images_dir."/".$filename );
    // First Create Thumbnail!
    // Thumbnail Settings
            
    $Config_tbwidth_wide 100// width of wide image
            
    $Config_tbheight_wide 75// height of wide image
            
    $Config_tbwidth_tall 75// width of tall image
            
    $Config_tbheight_tall 100// 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_".$filename );
    ImageDestroy($destination_handle );
    // .................................................................................
    // This is the new code that checks for width and solves our problems
    // .................................................................................
    // 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."/".$filename );
    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="admin.php">Back to Administration Page</a><br>
    $design_footer
    </body>
    </html>
    __HTML_END;
    //YOU WILL HAVE TO CHANGE THE LINK INFO TO REFLECT YOUR ENVIRONMENT (In the Print Result area only!)!
    ?>
    Drew

    "The town where I grew up has a zip code of E-I-E-I-O."

  6. #206
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drewf
    Ok Animal777 et all , I have spent a while learning how to solve the problem of getting my LARGE image files that excede my desired width (in this case 500 px wide) to be resized when uploaded. I have succeeded in my endevours and have included the code here for others to use.
    Drewf, You are the man! I tried this after I got your email. I works wonderfully. Now, can you fix the admin part to actually delete the images

  7. #207
    SitePoint Zealot soart's Avatar
    Join Date
    Nov 2003
    Location
    Norwich UK
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do wish that this tutorial had been called a photo album and not a gallery...a gallery in the art world has connotations of fine art...and this is an art gallery

    http://www.so-art.co.uk/merchant/index.php

    which will in a week or so have an auction module attached.

    I also wish that I had seen this tutorial before rewriting the old html site of this art gallery into php and mysql, might have saved a few sleepless nights wrestling with sessions and other stuff.

    On another thread there is a discussion about how you motivate to learn, well in this case I got Kevin Yanks 1st book and adapted and adapted and learnt more (uk.php.net) and adapted other already written code fragments and ideas from the net AND got some help from the users of this forum ....THANKS.....and CODED from a basic idea of database design to get it to work.

    I got to say though that learning C and C++ as a basis is almost a given
    to understand how to program neatly in the 1st place which is what I did at college.

    By the way I am a late 40's ex mature student who didn't start to learn to program until 3 years ago.

    True what they say, you never stop learning.

  8. #208
    SitePoint Enthusiast drewf's Avatar
    Join Date
    Mar 2002
    Location
    Calgary, AB
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by animal777
    Drewf, You are the man! I tried this after I got your email. I works wonderfully. Now, can you fix the admin part to actually delete the images
    Ah! You are welcome Yes I now will set my sights on this elusive admin feature of deleting the pictures (using the unlink() function) and maybe even moving the pictures from one category to another. I seem to think Mayank added some code about this a few pages back but I will have to reread this thread to see how we got here...he he.

    Anyhow I finally feel like I am learning something. Perhaps, just perhaps this PHP stuff is finally sinking in...nah! I won't go that far but I have a slight grin on my face

    As the Terminator said so elequently "I'll be back!"
    Drew

    "The town where I grew up has a zip code of E-I-E-I-O."

  9. #209
    SitePoint Enthusiast drewf's Avatar
    Join Date
    Mar 2002
    Location
    Calgary, AB
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nickthibert
    Hi there!

    Excellent code!

    I've been working with it for a while now to get everything configured etc... but I keep getting theses 2 errors whenever I go to the viewgallery.php page:


    Notice: Undefined index: cid in D:\proto\nick\viewgallery.php on line 9

    Notice: Undefined index: pid in D:\proto\nick\viewgallery.php on line 10

    I wrote it out myself and couldn't get it to work, and then even copy and pasted it from the .zip file for this code from this webpage and still get the same errors... Anyone? Please help, as I really like this page!
    This is a shot in the dark but I say this with a hunch, you might want to recheck your database structure. Perhaps you made an error when you created it. This is what I think your errors mean: I believe that once the photo is uploaded and is verified as a legit image in the checking arrary, and has its original file name which could be anything like "bobspictureofhimselfpickinghisnose.jpg" or what have you, the code will rename the original filename to a numerical file name with the correct image format suffix attached (HOLY RUN ON SENTENCE!-AH WHATEVER ). This new filename number is indexed in the database numerically. I believe that your errors are saying that it is unable to index this filename correctly. Either it is not present in the database structure itself or there is a problem with your code in this general area on the upload.php page:

    PHP Code:
    // 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); 
    Like I said, I could be wrong but I would "drop" your current database and copy and paste it into MySQL command program or GUI and redo it as in the tutorial on page 1. Also don't forget to add an initial entry for a testing database like the tutorial says to. I find that if I don't add this initial photo category I can not add any categories via the admin page...ho hum.

    Hopefully this puts you on the right track.
    Drew

    "The town where I grew up has a zip code of E-I-E-I-O."

  10. #210
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was having big trouble using unline so i ended up just running the command line rm function thru exec

    Least that method worked.

  11. #211
    SitePoint Enthusiast drewf's Avatar
    Join Date
    Mar 2002
    Location
    Calgary, AB
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Full finished distribution with all features attached

    Well everyone here is a full distribution of the photogallery script that is secure (requires a login of admin/admin which of course you should change ). It also incorporates the resize to predetermined width settings discussed above and ALL admin features work. Yes you read that correctly...updating photo captions and deleting photos included. Pretty much this is the whole ball of wax as far as I can tell except for sub-categories which I don't have a need for...sorry.

    This has the thumbnails set to 100% quality and the photos themselves set to 90% quality. In the upload.php page there are settings for these as an attribute to the $function_to_write function. Its the last attribute of the function-should be obvious to find if you wish to change it.

    Also the thumbnails are set to 150px wide and the full images are set to 500px wide. You should be able to figure out how to modify these settings too.

    This script also paginates when more than 8 thumbnails are put onscreen.

    It has dynamic redirection to a specified URL (from the database) built in too. This is a good feature that will let people view private galleries if you are inclined to expand the script with this feature in mind.

    You should not be able to get into any admin pages unless authorized...if I missed one just include the security.inc.php at the very beginning of your code on that page.

    Getting the design.inc.php to be included in your page is the tricky part. But once you get it into your design everything will be working peachykeen.

    Anyhow, enjoy. I hope this helps the people new to this thread...


    **update 3: if you downloaded my zip file and are having difficulty loging in to the photogallery, make sure there is no include("security.inc.php"); in the login.php page. For some reason I added it to this page without thinking. Anyhow I have updated the zip file above to reflect this change. I am just putting this blurb here incase someone downloaded it and can't get it to work...It should be working fine as I write this.

    **update 4: The username and password combo. to the admin area is admin/admin
    If you look at the SQL at the end of the file, there is a section called gallery_users. You can change the username and password here but as you can tell the password is formed using the PHP function MD5.
    Read up on the MD5 function here: http://ca3.php.net/md5

    I would also look up on the Net how to use PHPMyAdmin (http://www.phpmyadmin.net/home_page/) to administer MySQL databases using the web.


    phpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the Web. Currently it can create and drop databases, create/drop/alter tables, delete/edit/add fields, execute any SQL statement, manage keys on fields, manage privileges,export data into various formats and is available in 50 languages.
    Attached Files Attached Files
    Last edited by drewf; Jul 9, 2005 at 09:11. Reason: Pooched a file in the zip file
    Drew

    "The town where I grew up has a zip code of E-I-E-I-O."

  12. #212
    SitePoint Enthusiast drewf's Avatar
    Join Date
    Mar 2002
    Location
    Calgary, AB
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Noddy check this out for help with unlink()

    Quote Originally Posted by noddy
    I was having big trouble using unline so i ended up just running the command line rm function thru exec

    Least that method worked.
    Noddy check out my delete function and make sure you add the last unlink() statement. It deletes both the thumbnail and the large image. If I recall I think this was the problem you were having?

    PHP Code:
    function delete_photo($photo_id)
    {
    global 
    $images_dir;
    $result mysql_query("
       SELECT photo_filename
       FROM gallery_photos
       WHERE photo_id = '" 
    addslashes($photo_id) . "'
    "
    );
    list(
    $filename) = mysql_fetch_array($result);
    mysql_free_result($result);
    unlink($images_dir '/' $filename);
    unlink($images_dir '/tb_' $filename);
    mysql_query("
       DELETE FROM gallery_photos
       WHERE photo_id='" 
    addslashes($photo_id) . "'
    "
    );

    You should just examine my code in the .ZIP file. It does everything properly including using the unlink().

    Hope this helps.
    Drew

    "The town where I grew up has a zip code of E-I-E-I-O."

  13. #213
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my current delete photo functions

    PHP Code:
    function confirm_delete_photo() {
      global 
    $path,$title,$pid,$cid,$info;

      
    // this function makes the user confirm they want to delete the photograph
      
    $buf .= "<p>Are you sure you want to delete this photo?<br>\n";

      
    $buf .= "<form action=\"goto/do_delete_photo/pid/$pid\" method=\"POST\">\n";
      
    $buf .= "<input type=hidden name=pid value=\"$pid\">\n";
      
    $buf .= "<input type=hidden name=cid value=\"$cid\">\n";

      
    $buf .= "<input type=submit name=submit value=Submit> <a href=\"$_SERVER[HTTP_REFERER]\"><input type=button name=cancel value=Cancel></a>\n";

      
    $buf .= "</form>\n";

      return 
    msg($title,$buf);
    }

    // Deleting a photo
    function admin_delete_photo() {
      global 
    $title,$path,$cid,$pid,$info;

        
    $sql "DELETE FROM gallery_comments WHERE photo_id=\"$pid\"";
        
    mysql_query($sql)
          or 
    error("<span class=red>Could not delete an comments about the picture<br>".mysql_error()."<br>$sql</span><br>\n");

        
    $sql "SELECT photo_filename FROM gallery_photos WHERE photo_id=\"$pid\"";
        
    $res mysql_query($sql)
          or 
    error("<span class=red>There was an error while getting the image information.<br>".mysql_error()."<br>$sql</span>");
        
    //list($filename) = mysql_fetch_array($res);
        
    $row mysql_fetch_array($res);
        
    mysql_free_result($res);

        
    exec("rm $path[photos_dir]/$row[photo_filename]");
        
    exec("rm $path[photos_dir]/tb_$row[photo_filename]");

        
    //$buf .= "rm1: rm $path[photos_dir]$row[photo_filename]<br>\n";
        //$buf .= "rm2: rm $path[photos_dir]tb_$row[photo_filename]<br>\n";
        //$buf .= "image dir path".$path['photos_dir'] ."<br>\n";
        //$buf .= "image name: ".$row[0]."<br>\n";

        
    $sql "DELETE FROM gallery_photos WHERE photo_id=\"$pid\"";
        
    mysql_query($sql)
          or 
    error ("<span class=red>There was an error while deleteing the image record from the database.<br>".mysql_error()."</span>");

        
    $buf .= "<span class=green>Image is deleted.</span><br>\n";

        return 
    msg($title,$buf);

    I'm also able to add comments to photos in my gallery

  14. #214
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drewf
    This has the thumbnails set to 100% quality and the photos themselves set to 90% quality. In the upload.php page there are settings for these as an attribute to the $function_to_write function. Its the last attribute of the function-should be obvious to find if you wish to change it.
    I cannot upload more than 6 pictures. Is this due to a MB limit or a time limit? How many can you upload?

    should I look at using this?

    set_time_limit(0);

  15. #215
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in the php.ini file is a param

    upload_max_filesize you need to udjust this higher then.

  16. #216
    tammie
    SitePoint Community Guest
    I have error of "Undefined offset: 5 in c:\program files\apache group\apache\htdocs\gallery test\upload.php on line 34" - my line 34 is :
    if($photos_uploaded['size'][$counter] > 0).
    I am lost what am I doing wrong ?

  17. #217
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are many errors in this code.

    Warning: copy(/pictures/1.jpg): failed to open stream: No such file or directory in /home/e/p/epworthonline/public_html/gall/upload.php on line 51

    Warning: getimagesize(/pictures/1.jpg): failed to open stream: No such file or directory in /home/e/p/epworthonline/public_html/gall/upload.php on line 54

    Warning: Division by zero in /home/e/p/epworthonline/public_html/gall/upload.php on line 62

    Warning: imagecreatefromjpeg(/pictures/1.jpg): failed to open stream: No such file or directory in /home/e/p/epworthonline/public_html/gall/upload.php on line 72

    Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/e/p/epworthonline/public_html/gall/upload.php on line 84

    Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/e/p/epworthonline/public_html/gall/upload.php on line 85

    Warning: copy(/pictures/2.jpg): failed to open stream: No such file or directory in /home/e/p/epworthonline/public_html/gall/upload.php on line 51

    Warning: getimagesize(/pictures/2.jpg): failed to open stream: No such file or directory in /home/e/p/epworthonline/public_html/gall/upload.php on line 54

    Warning: Division by zero in /home/e/p/epworthonline/public_html/gall/upload.php on line 62

    Warning: imagecreatefromjpeg(/pictures/2.jpg): failed to open stream: No such file or directory in /home/e/p/epworthonline/public_html/gall/upload.php on line 72

    Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/e/p/epworthonline/public_html/gall/upload.php on line 84

    Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/e/p/epworthonline/public_html/gall/upload.php on line 85
    File 1 Added
    File 2 Added

  18. #218
    Steve
    SitePoint Community Guest
    This is great - reasonably easy to deploy (the only errors I got were from my typos - mainly whitespace in the __END_HTML lines).

  19. #219
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Calgary
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Drew et all.

    I'm having real trouble with the login (index.php) page. I can't seem to login. I've tried commenting out all references to the security file but that hasn't worked. Any suggestions?

  20. #220
    johnny choi
    SitePoint Community Guest
    I encountered the same problems as WellBaffled did. Anyone has the solution?

  21. #221
    SitePoint Zealot
    Join Date
    Jun 2001
    Location
    Earth
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cheazell
    Hi Drew et all.

    I'm having real trouble with the login (index.php) page. I can't seem to login. I've tried commenting out all references to the security file but that hasn't worked. Any suggestions?
    Hi, I just started yesterday to play around with the photo gallery script and today I downloaded drewf's modified version of it.
    I had the same problem as you cheazell, first I just changed the password with :
    mysql> update gallery_users set userPass=PASSWORD("newpassword")
    -> where userId=1 and userName="admin";
    mysql> flush privileges;


    by doing this however I was no more able to login as admin.

    Then I browsed in the MYSQL manual and found that there is another way to encrypt password using the MD5 encryption function, so I changed my sql query to
    mysql> update gallery_users set userPass=MD5('newpassword')
    -> where userId=1 and userName='admin';
    mysql> flush privileges;


    and now I can login as admin with the new password.
    Don't know if this can still help you, this is how I got it to work.
    Perhaps somebody else can help further.
    ciao

    -cla313
    cla313

  22. #222
    SitePoint Enthusiast drewf's Avatar
    Join Date
    Mar 2002
    Location
    Calgary, AB
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cla313
    Hi, I just started yesterday to play around with the photo gallery script and today I downloaded drewf's modified version of it.
    I had the same problem as you cheazell, first I just changed the password with :
    mysql> update gallery_users set userPass=PASSWORD("newpassword")
    -> where userId=1 and userName="admin";
    mysql> flush privileges;


    by doing this however I was no more able to login as admin.

    Then I browsed in the MYSQL manual and found that there is another way to encrypt password using the MD5 encryption function, so I changed my sql query to
    mysql> update gallery_users set userPass=MD5('newpassword')
    -> where userId=1 and userName='admin';
    mysql> flush privileges;


    and now I can login as admin with the new password.
    Don't know if this can still help you, this is how I got it to work.
    Perhaps somebody else can help further.

    -cla313
    I have pretty much abandoned PHP these days including this forum as my I find my time is thin so I am just following up quickly to cla313. cla313 you are bang on with your decision to encrypt the passwords using the MD5 function.

    In login.php there is a section at the top of the code that pretty much spells this out for you:

    look for these comments and the code below it:

    // Add slashes to the username, and make a md5 checksum of the password.

    Further down a few lines when starting the session:

    // We've already added slashes and MD5'd the password

    The MD5 function is used to encrypt the password for security purposes and is pretty difficult, if not impossible to decrypt in a human readable state. In otherwords, running this function is one way only and recovering the password is virtually impossible at least to the computing power of the average user...

    So yes, deleting or updating the passwords needs to be done either from the MySQL command line with the proper privaleges or from PHPMyAdmin with proper privaleges. I use PHPMyAdmin because I am a Windows kind of guy...

    Just make sure that when you are updating the password values (userPass) manually using PHPMyAdmin in the gallery_users table, you need to set the userPass value to an MD5 function using the function dropdown list box-if you don't you will give yourself errors.

    ***Note to readers experiencing errors***:

    I would reccomend reading this whole thread from beginning to end to really understand how some of us got to the points we are at with the original code. I just took the original code and extended it using a secure login script that I had used several times before in my projects. I would first try and get your code to work as its written in the tutorial before trying to use my code. I think by that point in time you will have a better understanding as to whats really going on before you mix in too many security related variables. Sessions are a pain in the *** when used with ZoneAlarm firewall for example. They will prevent you from logging in for example. I found this out the hard way...

    Another session pitfall is that you need a temporary storage directory for the sessions on the hard drive that is set in the PHP.INI file and is write accessable.

    Anyhow I am babbling on here...

    cla313, Good job getting the code to work.

    To everyone else, I can promise you that it does work just fine in the state as posted. Your errors are most likely due to one or more things usually being: PHP.INI configuration errors, typos, white space (in the PHP heredoc syntax) or gremlins in your machine (just kidding-I made that part up...).

    Hang in there everyone, I too am still a newbie and I know my code is not bullet proof. More experienced coders could most likely do what I did in a much more elegant and efficient way. If you are such a person, then please post your code for all to see.

    Good luck,
    --
    Drew
    Drew

    "The town where I grew up has a zip code of E-I-E-I-O."

  23. #223
    SitePoint Zealot
    Join Date
    Jun 2001
    Location
    Earth
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Drew,
    thanks for you thourogh reply. When I read your lines:
    Quote Originally Posted by drewf
    In login.php there is a section at the top of the code that pretty much spells this out for you:

    look for these comments and the code below it:

    // Add slashes to the username, and make a md5 checksum of the password.

    Further down a few lines when starting the session:

    // We've already added slashes and MD5'd the password
    I felt so ! I completely overlooked that! Meantime I have been pretty much digging into this whole thread and found a lot of good info.
    I am busy with getting previous/next image navigation included; I got it done (following Theo Molenaar directions in this thread), but I'm still kinda suffering on getting out the last $pid for a given cat (to add a "go to last picture" link in the single image navigation). Perhaps I overlooked also this, but I hope to get it solved.

    I want also to thank you and all the guys/girls which contributed so intensively to this project and of course Mayank for starting all this with his wonderful article.
    Keep on with the good work!
    cla313

  24. #224
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Europe
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I have trouble with code please help !!!

    First of all I am from Bosnia in Europe and i read the article
    Build An Automated PHP Gallery System In Minutes
    By Mayank Gandhi
    August 7th 2003
    Reader Rating: 9.1

    It's a very good artticle, but i have download the php code and then
    try try the code but in the start i have problems the problem is the preupload.php file. Of course before i create tables in my database and there are no problems in connecting the database.

    After running the page preupload.php to test it i get a error:

    Parse error: parse error, unexpected $end on line 67
    The line 67 is the list line in the code
    I didn't change anything in the orginal files that i downloaded from the web site.

    here is the code:

    ?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( $_GET['number_of_fields'] )
    $number_of_fields = (int)($_GET['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>
    __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;
    ?>

  25. #225
    SitePoint Zealot
    Join Date
    Jun 2001
    Location
    Earth
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if this is really the cause of the problem:

    • First line is <?php and not ?php
    • then you are missing include("security.inc.php");
      at the beginning of the file before include("design.inc.php");.


    Hope this helps.
    cla313


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
  •