How To Display Link Of Uploaded Pdf Files?

Hi All,

Uploaded pdf files using;

Controller




public function uploadMultifile ($model,$attr,$path)

            {

                if($sfile=CUploadedFile::getInstances($model, $attr)){

                  foreach ($sfile as $i=>$file){  

                     $formatName=time().$i.'.'.$file->getExtensionName();

                     $file->saveAs(Yii::app()->basePath .DIRECTORY_SEPARATOR.'..'. $path.$formatName);

                     $ffile[$i]=$formatName;

                     }

                    return ($ffile);

                 }

             }


public function actionCreate()

	{

		$model=new Scaffold;

                $model->date_erected = date('Y-m-d');


		// Uncomment the following line if AJAX validation is needed

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


		if(isset($_POST['Scaffold']))

		{

			$model->attributes=$_POST['Scaffold'];

                            if($filez=$this->uploadMultifile($model,'material_list','/uploads/materials/'))

                                {

                                $model->material_list=implode(",", $filez);

                                }

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


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

			'model'=>$model,

		));

	}



Model




public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

                        array('material_list', 'file', 'types'=>'jpg,jpeg,doc,docx,xls,xlsx,pdf',

                                'maxSize'=>1024 * 1024 * 3, // 3MB

                                'tooLarge'=>'The file was larger than 3MB. Please upload a smaller file.',

                                'allowEmpty' => true),			

		);

	}



_form view




<div class="row">

                <?php echo $form->labelEx($model,'material_list'); ?>

                <?php  $this->widget('CMultiFileUpload',

                    array(

                         'model' => $model,

                         'attribute' => 'material_list',

                         'accept' => 'jpg|jpeg|doc|docx|xls|xlsx|pdf',

                         'denied' => 'Only jpg,jpeg,doc,docx,xls,xlsx and pdf are allowed', 

                         'max' => 3,

                         'remove' => '[x]',

                         'duplicate' => 'Already Selected',


                ));?>

                <?php echo $form->error($model,'material_list'); ?>

                <div class="hint">You can upload up to 3 attachments. </div>

        </div>



How to display link of uploaded pdf files in view (CDetailView) for viewing and download?

And also how to remove or replace the file in Update action?

Hi you can set the oncomplete event after uplaod iamge




'onComplete' => "js:function(id, fileName, responseJSON){

            jQuery('.qq-upload-list').html('');

            // alert(responseJSON);

            var filename = responseJSON['filename'];

            var success = responseJSON['success'];

           if(success == true) {

             

                jQuery('#displayvenuefloorimage1').html('<a target=\'_blank\' class=\'mleft15 blue\' href=" . Yii::app()->baseUrl . '/upload/venue_floor/' . "'+filename+'>View Floor Plan</a><div class=\'deleteImage ptop0 active float_r\'><img onclick=\'removeVenueFloor(\"'+filename+'\");\' src=" . Yii::app()->baseUrl . "/images/delete_image.png alt=\'Remove image\'></div>');

                

                $('#displayvenuefloorimage1 a').css('text-decoration', 'underline');

                

            }else{

           

            }

        }",

and remove the folder you want to use unlink function

for e.g





$folder = YiiBase::getPathOfAlias('webroot') . '/upload/event/' . $_POST['imagename'];

if (file_exists($folder) && $_POST['imagename'] != "") {

  @unlink($folder);

  @unlink(YiiBase::getPathOfAlias('webroot') . '/upload/event/' . $_POST['imagename']);

}

Hi Maggie Q,

Thanks for your reply but where do I put this codes? I noticed that this is for image, is it applicable for other format? I’m a newbie to yii, php and basically to programming.

What code should I put on ‘material_list’ to display the link?




<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

                //'id',

                array(

                    'name' => 'department_id',

                    'value' => $model->department->name

                ),      

                array(        

                    'name' => 'facility_id',

                    'value' => $model->facility->name

		),

		'location',

                array(        

                    'name' => 'type_id',

                    'value' => $model->type->name

		),

                array(        

                    'name' => 'duty_id',

                    'value' => CHtml::encode($model->getDutyText())

		),

		array(        

                    'name' => 'status_id',

                    'value' => CHtml::encode($model->getStatusText())

		),

		'weight',

		'work_order',

		'erect_manhrs',

		'dismantle_manhrs',

		'date_erected',

		'inspection_date',

		'date_dismantled',

		'requested_by',

		'built_by',

                'other_details',

                array(        

                    'name' => 'deluge_id',

                    'value' => CHtml::encode($model->getDelugeText())

		),

		array(        

                    'name' => 'los_id',

                    'value' => CHtml::encode($model->getLosText())

		),

		array(        

                    'name' => 'deboard_id',

                    'value' => CHtml::encode($model->getDeboardText())

		),

                'material_list',              

		'create_time',

                array(        

                    'name' => 'create_user_id',

                    'value' => $model->createUser->username

		),

		'update_time',

                array(        

                    'name' => 'update_user_id',

                    'value' => $model->updateUser->username

		),     

	),

)); ?>



Please provide example using my data, thanks again.

Anyone out there please help.