TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Error on Upload::image explanation
  • Hello, I would like to report a little issue with this:

          /**
         * Validation rule to test if an upload is an image and, optionally, is the correct size.
         *
         *     // The "image" file must be an image
         *     $array->rule('image', 'Upload::image')
         *
         *     // The "photo" file has a maximum size of 640x480 pixels
         *     $array->rule('photo', 'Upload::image', array(640, 480));
         *
         *     // The "image" file must be exactly 100x100 pixels
         *     $array->rule('image', 'Upload::image', array(100, 100, TRUE));
         *
         *
         * @param   array    $_FILES item
         * @param   integer  maximum width of image
         * @param   integer  maximum height of image
         * @param   boolean  match width and height exactly?
         * @return  boolean
         */
        public static function image(array $file, $max_width = NULL, $max_height = NULL, $exact = FALSE)
        {
            if (Upload::not_empty($file))
            {
                try
                {
                    // Get the width and height from the uploaded image
                    list($width, $height) = getimagesize($file['tmp_name']);
                }
                catch (ErrorException $e)
                {
                    // Ignore read errors
                }
    
                if (empty($width) OR empty($height))
                {
                    // Cannot get image size, cannot validate
                    return FALSE;
                }
    
                if ( ! $max_width)
                {
                    // No limit, use the image width
                    $max_width = $width;
                }
    
                if ( ! $max_height)
                {
                    // No limit, use the image height
                    $max_height = $height;
                }
    
                if ($exact)
                {
                    // Check if dimensions match exactly
                    return ($width === $max_width AND $height === $max_height);
                }
                else
                {
                    // Check if size is within maximum dimensions
                    return ($width 

    This is on system/classes/kohana/upload.php in Kohana v3.2. The issue is with te explanation of the function:

         *     // The "photo" file has a maximum size of 640x480 pixels
         *     $array->rule('photo', 'Upload::image', array(640, 480));
         *
         *     // The "image" file must be exactly 100x100 pixels
         *     $array->rule('image', 'Upload::image', array(100, 100, TRUE));
    

    Instead of that the text should be:

         *     // The "photo" file has a maximum size of 640x480 pixels
         *     $array->rule('photo', 'Upload::image', array(':value', 640, 480));
         *
         *     // The "image" file must be exactly 100x100 pixels
         *     $array->rule('image', 'Upload::image', array(':value', 100, 100, TRUE));