Skip to content

Instantly share code, notes, and snippets.

@chrismeller
Created September 19, 2011 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismeller/1226715 to your computer and use it in GitHub Desktop.
Save chrismeller/1226715 to your computer and use it in GitHub Desktop.
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