Skip to content

Instantly share code, notes, and snippets.

@chrismeller

chrismeller/five.php

Created Sep 19, 2011
Embed
What would you like to do?
Validating File Uploads in Kohana 3.2
echo Form::open( null, array( 'enctype' => 'multipart/form-data' ) );
$errors = Arr::merge( $post->errors( 'some/messages/post' ), $file->errors( 'some/messages/file' ) );
$post = Validation::factory( $_POST );
$file = Validation::factory( $_FILES );
if ( Request::current()->method() == Request::POST && $post->check() && $file->check() ) {
// the request is valid, do your processing
// save the uploaded file with the name 'form' to our destination
$filename = Upload::save( $file['form'] );
if ( $filename === false ) {
throw new Exception( 'Unable to save uploaded file!' );
}
}
$file->rule( 'form', array( 'Upload', 'not_empty' ) );
$file->rule( 'form', array( 'Upload', 'valid' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.