After quite a quiet spell I am once again able to post a quick tip and share a little of what I've learnt in the world of web development. I hope this post will prove helpful to someone. Please note that in this tip I'm assuming that you have used Kohana's Validation Library before and you found this tip after having problems with upload validation. Kohana's validation library is pretty cool and can do all sorts of things that would take a bit of time using 'standard PHP.'

Suppose you wanted your image upload code to check that a user had actually selected an image to upload before attempting to manipulate the image or save the image data to the database. Now, for standard fields, the validation library uses code similar to the following:

            $post = new Validation(array_merge($_POST,$_FILES));
            $post->pre_filter('trim');
            $post->add_rules('name','required');

When I tried to require that an upload be required, using this code, I was unable to. Alas after a bit of head-scratching and keyword permutation trials, I found you need to specify upload::required among your validation rules. Hence the following code:

            $post->add_rules('profileimage','upload::required','upload::valid', 'upload::type[jpg]', 'upload::size[1M]');

Well, folks, that's all I have time for today, and if you don't understand this code, you will need to look at the Validation library as I stated at the beginning of the article. I hope this helps someone out there.

Feel free to post back and let me know if this code helped in any way.