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?