mandag den 30. september 2013

How to upload a file using a model

http://www.yiiframework.com/wiki/2/how-to-upload-a-file-using-a-model/

validating the file size:
 
In the model, in the rules functions add this line
 
 /**
  * @return array validation rules for model attributes.
  */
 public function rules()
 {
  // NOTE: you should only define rules for those attributes that
  // will receive user inputs.
  return array( 
                    array(
                      'yourfile', 
                      'file', 
                      'types'=>'jpg, gif, png, jpeg',  
                      'maxSize'=>1024 * 1024 * 50,  
                      'tooLarge'=>'File has to be smaller than 50MB'
                    ),
                .....
                .....
                .....
                ); 
        }

Ingen kommentarer:

Send en kommentar