H
H
hollanditkzn2017-06-16 16:44:54
Yii
hollanditkzn, 2017-06-16 16:44:54

Who will help to deal with the fileInput widget?

I'm using the demos.krajee.com/widget-details/fileinput widget. And I have a problem that when uploading files, it is necessary that ajax is immediately uploaded to the server. As let's say vkontakte, gmail and other places before sending files and then quickly sends. So that when saving the file, you do not have to wait long. Now input type=file, when 20 MB is loaded, the debt page is loaded and it may completely exit that the waiting time has been exceeded, and you have to go back and re-enter all the data. I need it so that when the user loads it is acceptable with a bad Internet connection and there is a bar process at the same time. Where the user saw how much was downloaded when the download was completed and quickly could simply save the data to the database, and the file is already on the server.
I settled on the fact that the page simply reloads when you click download and that's it. Here is the code

<?=$form->field($models, 'file')->widget(FileInput::className(), [
            'name' => 'input-ru[]',
            'options' => ['multiple' => false],
            'language' => 'ru',
            'pluginOptions' => [
                'uploadeUrl' => Url::to(['zakaz/uploade', 'id' => $models->id_zakaz]),
                'showPreview' => false,
                'previewFileType' => 'any',
                ]
        ]) ?>

And yes, after saving, I have questions, how to get the name of the file that was saved
In the controller, I wrote like this
public function actionUploade($id){
        $model = $this->filndModel($id);
        $model->file = UploadedFile::getInstance($model, 'file');
        $model->upload();
        $model->img = time().'.'.$model->file->extension;
    }

public function actionZakazedit($id){

        $models = $this->findModel($id);

        if($models->load(Yii::$app->request->post()) && $models->save()){
            return $this->redirect(['admin', '#' => $models->id_zakaz]);
        } else {
        return $this->renderAjax('_zakazedit', ['models' => $models]);
        }
    }

In the model
public function upload()
    {
        if($this->file){
        $this->file->saveAs('attachment/'.time().'.'.$this->file->extension);
        return true;
        } else {return false;}
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question