dimis283
(Dimis283)
1
I am trying to upload a file with CActiveForm but when I write
print_r($_files);die();
there is an empty array.
what is wrong?
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'ind-pdf-form',
'enableAjaxValidation'=>false,
'htmlOptions' =>array(type=>"multipart/form-data" )
)); ?>....
<?php echo $form->fileField($model,'title'); ?>
dimis283
(Dimis283)
2
I solve that problem but now the file is not uploaded.
And also I have the error
Ind_pdfController does not have a method named "addError".
what is wrong?
$model=new ind_pdf;
...
if(isset($_POST['ind_pdf'])) {
Yii::import('application.extensions.upload.Upload');
//print_r($_FILES);die();
$model->attributes=$_POST['ind_pdf'];
$Upload = new Upload( (isset($_FILES['ind_pdf']['title']) ?$_FILES['ind_pdf']['title'] : null) );
$destPath = Yii::app()->getBasePath().'/../pdf/';
$Upload->process($destPath);
if ($Upload->processed) {
$model->title = $Upload->file_dst_name;
if($model->save())
$this->redirect(array('view','id'=>$model->code));
}
else
$model->addError('title',$Upload->error);
[EDIT] I solved it .
alexserver
(Alexserverone)
4
Yeah, please, could you tell us how did you solve the problem ?
iivano71
(Igor Zg1987)
5
$destPath = Yii::app()->getBasePath().'/../pdf/';
Problem was in destination path this is not alowed
I´ve solved the problem with the empty array by changing $_POST to $_FILES
dimis283
(Dimis283)
7
Here is a tutorial.
I used it and I do a custom validation if needed, checking the $_FILES array because I had the "Image cannot be blank" problem as mentioned there.