Yii CMultiFileUpload mehrere Dateien auswählen

Bekam Die Antwort

Hochladen von mehreren Dateien in der Datenbank für die Registrierung
habe versucht so viele Möglichkeiten, um mehrere Datei-upload praktikabel mit CMultiFileUpload widget. Schon, ich habe überprüft und folgte unten links-

http://www.yiiframework.com/forum/index.php/topic/47665-multiple-file-upload/

Yii mehrere Datei-upload

ABER noch kein Glück!!

Fehler: die Speicherung der Daten, aber die Dateien sind nicht hochgeladen bekommen
bitte helfen
Hier ist mein code:

In Form

<?php  $this->widget('CMultiFileUpload',
        array(
                   'model'=>$model,
                   'attribute' => 'documents',
                   'accept'=>'jpg|gif|png|doc|docx|pdf',
                   'denied'=>'Only doc,docx,pdf and txt are allowed', 
                   'max'=>4,
                   'remove'=>'[x]',
                   'duplicate'=>'Already Selected',

                )
);?>

- Controller-Code

public function actionRegistration()
    {
        $model=new PatientRegistration;

        $this->performAjaxValidation($model);

        if(isset($_POST['PatientRegistration']))
        {
            $model->attributes=$_POST['PatientRegistration'];
            if($model->validate())
            {
                if(isset($_POST['PatientRegistration']))
                {
                    if($filez=$this->uploadMultifile($model,'documents','/Images/'))
                    {
                        $model->documents=implode(",", $filez);
                    }
                    $model->attributes=$_POST['PatientRegistration'];
                    if($model->save())
                    {
                        // $this->render('registration',array('model'=>$model));
                        $this->redirect(array('/patientregistration/patientview','id'=>$model->register_id));
                    }
                }
            }
        }
        $this->render('registration',array('model'=>$model));
    }
    public function uploadMultifile($model,$attr,$path)
    {
        /*
         * path when uploads folder is on site root.
         * $path='/uploads/doc/'
         */
        if($sfile=CUploadedFile::getInstances($model, $attr)){
            foreach ($sfile as $i=>$file){
                //$formatName=time().$i.'.'.$file->getExtensionName();
                $fileName = "{$sfile[$i]}";
                $formatName=time().$i.'_'.$fileName;
                $file->saveAs(Yii::app()->basePath.$path.$formatName);
                $ffile[$i]=$formatName;
            }
            return ($ffile);
        }
    }

Fügen Sie in CActiveForm widget

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

Damit u kann diesen code verwenden, um das hochladen mehrerer Dateien in yiiframework

  • Es ist am besten, um die Antwort auf deine eigene Frage mit der Lösung, die Sie gefunden. Anderen Menschen geholfen werden könnte als gut.
InformationsquelleAutor sandeep | 2014-02-18
Schreibe einen Kommentar