Created
September 19, 2011 15:08
-
-
Save chrismeller/1226715 to your computer and use it in GitHub Desktop.
Validating File Uploads in Kohana 3.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo Form::open( null, array( 'enctype' => 'multipart/form-data' ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$errors = Arr::merge( $post->errors( 'some/messages/post' ), $file->errors( 'some/messages/file' ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$post = Validation::factory( $_POST ); | |
$file = Validation::factory( $_FILES ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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