coppermine-gallery.com/forum

Support => cpg1.3.x Support => Older/other versions => cpg1.3 Upload => Topic started by: ganeshcp on November 23, 2005, 08:48:50 PM

Title: minimum height/width
Post by: ganeshcp on November 23, 2005, 08:48:50 PM
I don't want pictures that are too small in my gallery so I modified the hard code to check pic for a minimum width and height. I'm only an amateur php programmer....this code doesn't seem to work, small pictures are still getting uploaded without any error. Its too late in the night for me to spot any sill errors....hopefully someone can help  ???

        // Check that picture file size is lower than the maximum allowed
        if (filesize($uploaded_pic) > ($CONFIG['max_upl_size'] << 10)) {
            @unlink($uploaded_pic);
            cpg_die(ERROR, sprintf($lang_db_input_php['err_imgsize_too_large'], $CONFIG['max_upl_size']), __FILE__, __LINE__);
        } elseif (is_image($picture_name)) {
            $imginfo = getimagesize($uploaded_pic);
            // getimagesize does not recognize the file as a picture
            if ($imginfo == null) {
                @unlink($uploaded_pic);
                cpg_die(ERROR, $lang_db_input_php['err_invalid_img'], __FILE__, __LINE__, true);

            // JPEG and PNG only are allowed with GD
            } elseif ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($CONFIG['thumb_method'] == 'gd1' || $CONFIG['thumb_method'] == 'gd2')) {
                @unlink($uploaded_pic);
                cpg_die(ERROR, $lang_errors['gd_file_type_err'], __FILE__, __LINE__, true);

            // *** NOT NEEDED CHECK DONE BY 'is_image'
            // Check image type is among those allowed for ImageMagick
            //} elseif (!stristr($CONFIG['allowed_img_types'], $IMG_TYPES[$imginfo[2]]) && $CONFIG['thumb_method'] == 'im') {
                //@unlink($uploaded_pic);
                //cpg_die(ERROR, sprintf($lang_db_input_php['allowed_img_types'], $CONFIG['allowed_img_types']), __FILE__, __LINE__);

            // Check that picture size (in pixels) is very low.
            }  elseif ($imginfo[0] < '150') {
                @unlink($uploaded_pic);
                cpg_die(ERROR, sprintf($lang_db_input_php['err_fsize_too_small_width']), __FILE__, __LINE__);
    } elseif ($imginfo[1] < '200') {
                @unlink($uploaded_pic);
                cpg_die(ERROR, sprintf($lang_db_input_php['err_fsize_too_small_height']), __FILE__, __LINE__);


            // Check that picture size (in pixels) is lower than the maximum allowed
            } elseif (max($imginfo[0], $imginfo[1]) > $CONFIG['max_upl_width_height']) {
                @unlink($uploaded_pic);
                cpg_die(ERROR, sprintf($lang_db_input_php['err_fsize_too_large'], $CONFIG['max_upl_width_height'], $CONFIG['max_upl_width_height']), __FILE__, __LINE__);
            }


Title: Re: minimum height/width
Post by: kegobeer on November 23, 2005, 09:56:46 PM
Try searching the forums - I believe I coded a minimum requirement and posted it quite a while ago.
Title: Re: minimum height/width
Post by: ganeshcp on November 24, 2005, 09:50:07 AM
hi,

the topic dealing with this is at:
http://forum.coppermine-gallery.net/index.php?topic=18556.0

i got the idea for the code from that topic only. i found some mistakes in my previous code...i simplified it further...but its still not working....it just uploads the (small) pic with no problems!!

its as though it doesn't even check for the condition

added in db_input.php

            } // Image is ok
        }

    // check to see if width or height is small than 200 pixels.
    if (min($imginfo[0], $imginfo[1]) < 200) {
                @unlink($uploaded_pic);
                cpg_die(ERROR, sprintf($lang_db_input_php['err_fsize_too_small']), __FILE__, __LINE__);
            }
Title: Re: minimum height/width
Post by: ganeshcp on November 25, 2005, 07:05:25 AM
gosh can someone help with this? it is important for my gallery  ???
Title: Re: minimum height/width
Post by: Nibbler on November 25, 2005, 03:41:35 PM
Please post a link and test user account for help with upload issues. Note that the file db_input.php is used only for 'single file upload' type uploads. If you are using some other uploading method then the relevent code would be elsewhere.
Title: Re: minimum height/width
Post by: ganeshcp on November 25, 2005, 05:04:02 PM

i solved the problem  ;D
yes that was the problem. today when i was relooking the issue i realized that multi file uploads are handled by upload.php. Here is the code for those who want help with this issue (note: this is a hard code and values cannot be modified from admin)

add after
                } elseif (max($imginfo[0], $imginfo[1]) > $CONFIG['max_upl_width_height']) {
                    @unlink($path_to_image);

                    // The file upload has failed -- the image dimensions exceed the allowed amount.
                    $file_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'file_name'=> $file_name, 'error_code'=>$lang_upload_php['pixel_allowance']);

                 // There is no need for further tests or action, so skip the remainder of the iteration.
                continue;
                }


       // check for minimum width
                elseif ($imginfo[0] < 150) {
                @unlink($uploaded_pic);
                    $file_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'file_name'=> $file_name, 'error_code'=>$lang_upload_php['pixel_small_width']);

                 // There is no need for further tests or action, so skip the remainder of the iteration.
                continue;
                }


                // check for minimum height
                elseif ($imginfo[1] < 200) {
                @unlink($uploaded_pic);
                    $file_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'file_name'=> $file_name, 'error_code'=>$lang_upload_php['pixel_small_height']);

                 // There is no need for further tests or action, so skip the remainder of the iteration.
                continue;
                }


the above code should also be added for url uploads after

                    // The file upload has failed -- the image dimensions exceed the allowed amount.
                    $URI_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $_POST['URI_array'][$counter], 'error_code'=>$lang_upload_php['pixel_allowance']);

                // There is no need for further tests or action, so skip the remainder of the iteration.
                 continue;

                }


further the variables pixel_small_height and pixel_small_width should be added to ur language file under upload.php.

:)