Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:35:05+00:00 2026-06-18T15:35:05+00:00

I am using code below for file validation. Strange thing is that if I

  • 0

I am using code below for file validation. Strange thing is that if I am trying to upload file which is above size limit I get not empty error instead of error related to size limit. Can anyone explain where is the problem ?

$validate = Validate::factory($_FILES);
             $validate->rules('image',
                     array(
                     'Upload::valid' => array(),
                     'Upload::not_empty' => array(), 
                     'Upload::type' =>array('Upload::type' => array('jpg','png','gif')), 
                     'Upload::size' => array('1M'))
                     );


             if ($validate->check())
            {           
             //ok
             $directory = DOCROOT.'uploads/';
             $filepath = Upload::save($_FILES['image'], '123zxhahaxdfdgsdfsdha.jpg', $directory);   
             Request::instance()->redirect($redirect);                  
            }
             else
             {
             //error    
                 $this->errors = $validate->errors('errors');
                 $errors = $this->errors;
             //echo $errors;
             }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:35:07+00:00Added an answer on June 18, 2026 at 3:35 pm

    You can fix this by changing the order of the elements in your validation array, i.e. change

    $validate->rules(
        'image',
        array(
            'Upload::valid' => array(),
            'Upload::not_empty' => array(), 
            'Upload::type' =>array('Upload::type' => array('jpg','png','gif')), 
            'Upload::size' => array('1M'),
        )
    );
    

    to

    $validate->rules(
        'image',
        array(
            'Upload::valid' => array(),
            'Upload::size' => array('1M'),
            'Upload::not_empty' => array(), 
            'Upload::type' =>array('Upload::type' => array('jpg','png','gif')), 
        )
    );
    

    “Wut‽”, you may well have thought. Well, the way validation rules are processed in Kohana, the checker stops checking for more rules. If you want to see this for yourself, look for these lines in system/classes/kohana/validate.php:

        //This field has an error, stop executing rules.
        break;
    

    You’ll find them in Kohana 3.0, which you appear to be using, but also in the current 3.3.

    And you were, presumably, testing your application by uploading a file with size large enough to be blocked by PHP or even by your web server. The most likely culprit is PHP’s upload_max_filesize value, which in default PHP installations is only 2M, cf. this page from the PHP manual. This would mean that the file upload IS empty (as in, there is no file) because of being blocked by PHP for being too big.

    That would explain why your code was giving the behaviour you reported. But Kohana’s Upload::size function is (of course!) clever enough to detect that the file size is too big — you’ll find these lines in system/classes/kohana/upload.php:

        if ($file['error'] === UPLOAD_ERR_INI_SIZE)
        {
            // Upload is larger than PHP allowed size
            return FALSE;
        }
    

    So if it checks that first, it will fail on that rule, which is why my re-shuffling of your code should get rid of the unwanted behaviour you reported.

    Two other, tangential, remarks:

    Firstly, in system/classes/kohana/upload.php you will notice this comment:

    If you _do_ require a file to be uploaded, add
    the [Upload::not_empty] rule before this rule.
    

    But I’ve not taken that before into account when re-ordering your validation rules because TBH I think it’s misleading/incorrect: surely you want to check that the upload is valid, i.e. that all the array fields are set, before doing tests on the values of those fields.

    Secondly, note that Upload::not_empty does not check that the file size is greater than zero; to make it do that you could create application/classes/upload.php with the following content:

    class Upload extends Kohana_Upload {
    
        public static function not_empty(array $file)
        {
            return (parent::not_empty($file)
                AND $file['size']);
        }
    
    }
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using code below to upload large file to server and noticed that
I am trying to load a JS file using yepnope using the below code:
How do I browse to upload a file using Dojo? See the code below:
im trying to extract some files from a jar-file downloaded using java-webstart. below code
I am trying to compile an object file using the code below. //--Begin test.cpp
Below is the code that I am using: This is my app/models file: class
I am creating excel file using below code public class ResultSetToExcel { private HSSFWorkbook
I am using the code below to download an Excel file. Once the Response.End()
I 'm opening a video file (3gp) file using code below String url =
I have swf file, im using code below to display it on my website:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.