Using Images Uploaded In Folder

Hey all,

Am working on a project that involve uploading scanned Identity cards of the Applicants. The system collects residential and employment details of the applicant. A pdf report containing summary of that application is sent to some email address for processing. Up to this point everything works perfectly but i am unable to include the scanned ID as part of this pdf report. I successfully implemented the upload functionality and the file name to db. Including the image to the pdf report is the problem. I Have attached a pdf document to clarify what i mean. please have a look at it.

My controller


class UploadController extends Controller


	public function actionIndex()


		$command = Yii::app()->db->createCommand();


		$model=new Upload();


		$dir = Yii::getPathOfAlias('application.uploads');

		$uploaded = false;










				$uploaded = $file->saveAs($dir.'/'.$file->getName());




				//$dest_name = md5($model->filename=$file->getName());



				//$file->saveAs(Yii::app()->getBasePath() . '/../images/dbImages/' . '1.jpg');




	$this->render('index', array(

	'model' => $model,

	'uploaded' => $uploaded,

	'dir' => $dir,




my model


 class Upload extends CActiveRecord


	public $file;

	public function rules()


		return array(





I have a controller named PdfController and I use Mpdf for conversion of html to pfd. I instantiate the Upload model in it to help me get data in that model in this case the uploaded image.

Like this



$mPDF1->WriteHTML($this->renderPartial('summary', array('pi'=>$PI,'pa'=>$PA,'ei'=>$EI,'pb'=>$PB,'up'=>$UP), true));


And finally i try to echo the Image like this

Applicants Id Photo :

<?php echo $up->filename; ?>

This Doesn’t work for me.

Please help

Thanks in advance.

  1. Just to make it clear: are the images actually uploaded to your server, and is the table "filename" field correctly populated?

  2. n your view form widget properties, have you set the enctype property to multi-part/form-data?

  1. What do you mean by echoing the image? Actually display it or echoing the value of the field?

PS I’m confused, the PDF you’ve attached does include an image… So is it what you intend to have, or have you solved your problem?

Thanks buddy for the reply. The images are successfully uploaded to the server and filename also successfully correctly populated. Sorry I meant displaying the image.

The pdf i attached is to help me illustrate where i want the image displayed. Other details in blue color are successfully pulled from the db.

I have attached another pdf, the actual report sent to the organization for processing. As u can see it doesn’t have the scanned image National Identity Card. So problem not solved and yes that’ s what i intend to have/ achieve. Give me a hand on this buddy, got deadline on Tuesday.

Thanks in advance

Ok, so I guess

<?php echo $up->filename; ?>

just writes down the file name in your pdf, right?

That’s normal, if you want to include it as an image, you can write the HTML tag for it, or use Yii’s CHtml::image.

Writing the filename would mean the image will be static but it should be dynamic so that every user will have his image pulled from from the db. May be a variable would do better

I think there’s miscommunication here… You can forget my remark. Let me rephrase my answer:

Instead of

<?php echo $up->filename; ?>

you should render an img HTML tag with the (dynamically-retrieved) filename as an attribute. You can use Yii helper for that (CHtml::image()), which I gave you the link for.

Thanks man