File Is Not Being Uploaded

Hello there,

I am using following method to upload and convert the pdf file using image magic. The create method is working but the image is not being uploaded in the respective directory.

public function actionCreate()


	$model=new Alerts;

	// Uncomment the following line if AJAX validation is needed

	// $this->performAjaxValidation($model);





                    $pdf_file = $model->infoFile->name;

                    $save_to = $model->getUploadPath()."sample.jpg";


// exec(‘convert $model->infoFile->name -colorspace RGB $model->getUploadPath().$image’,$output,$return_var);

                         exec('convert "'.$pdf_file.'" -colorspace RGB -resize 800 "'.$save_to.'"', $output, $return_var);

// Yii::log($model->infoFile,‘trace’,‘application’);

// Yii::log($model->getUploadPath(),‘info’);

// $model->infoFile->saveAs($model->getUploadPath().$model->infoFile->name);








Could you please suggest what could be the issue.

I can assure that webserver has write permission to $model->getUploadPath() which is Yii::getPathofAlias(‘webroot’).’/uploads/’; and Image Magic is properly installed and configured in the webserver

In your _form.php partial view do you have the following line added to your CActiveForm widget:

'htmlOptions' => array('enctype' => 'multipart/form-data'),

In all it should look similar to:

<?php $form = $this->beginWidget('CActiveForm', array(



    'htmlOptions' => array('enctype' => 'multipart/form-data'

)); ?>

Yes My form look like this

<?php $form=$this->beginWidget(‘bootstrap.widgets.TbActiveForm’,array(




    'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'),

)); ?>

I missed this before, I believe you want to change:

$pdf_file = $model->infoFile->name;


$pdf_file = $model->infoFile->tempName;

The name property is just the filename whereas tempName is the complete path.

Also make sure you have a rule for your property infoFile.

No luck with the tempName as well and I do have rule for infoFile which is as follows:





$pdf_file = CUploadedFile::getInstance($model,'infoFile'); //Gets object of uploaded file and assigns to $pdf_file var



$pdf_file_name = $pdf_file->name; //Create another var and assign only the file name to it

$model->infoFile = $pdf_file_name; //Assign the file name to the model attribute, so that the same as is saved to db

$save_to = $model->getUploadPath()."sample.jpg";




$pdf_file->saveAs($save_to); //Run the saveAs on the $pdf_file object and save the file to the save path defined above

//Now that the file has been saved to the folder, and the file name to the db, run any other image manipulation code here

// exec('convert $model->infoFile->name -colorspace RGB $model->getUploadPath().$image',$output,$return_var);

// exec('convert "'.$pdf_file.'" -colorspace RGB -resize 800 "'.$save_to.'"', $output, $return_var);

// Yii::log($model->infoFile,'trace','application');

// Yii::log($model->getUploadPath(),'info');




What is the point. I Want to save the image file not the pdf file.

I have found the solution. actually my ghostscript was not properly installed. I have re-install the ghost script and now everything is working fine.


Ashish Tyagi