hello , am new to Yii…
i am uploading file in my user form what i want is , my uploaded file should be view on the form beside that field only before creation of user… that field is not compulsory in my validation…
and one more thing i need to keep its size in kb only…
wally
(Fosales)
January 31, 2015, 6:03pm
2
encyclopedia:
hello , am new to Yii…
i am uploading file in my user form what i want is , my uploaded file should be view on the form beside that field only before creation of user… that field is not compulsory in my validation…
and one more thing i need to keep its size in kb only…
to validate the file size:
public function rules() {
return array(
array('fileName', 'file', 'maxSize' => 1024 * 1024 * 3), //3mb
);
}
to save your file with the model:
$postedData = $_POST['Class'];
$model->setAttributes($postedData);
$model->fileName = CUploadedFile::getInstance($model, 'fileName');
$model->nm_fileName = $model->fileName->getName();
$path = 'files/' . $model->nm_fileName;
if ($model->save() && $model->fileName->saveAs($path)) {
/**/
}
what should i do to view my uploaded file onclick of ‘view’ text or button before creation of record…
wally
(Fosales)
February 3, 2015, 1:41pm
5
I think you need to follow two steps: one for the upload, another to save the model.
sorry but i didn’t understand what you want to say??
wally
(Fosales)
February 5, 2015, 12:14am
7
Sorry, maybe i did not understand what you need . Do you want to show a file (by example, like an image) to user, before you save the model?