C
C
ch-aqwer2017-06-05 21:23:17
Yii
ch-aqwer, 2017-06-05 21:23:17

What's wrong with the code, YII2?

Good evening! Please explain what is wrong with this code. It should store and output files. (Yii2, multiple file) Already brains boil.

<?php
use yii\helpers\Html;
use yii\helpers\Url;
use kartik\file\FileInput;
if (! $model->isNewRecord) {
echo $form->field($files, 'files')->widget(FileInput::classname(), [
    'options'=>[
        'multiple'=>true
    ],
    'pluginOptions' => [
    	'showCaption' => true,
    	'showUpload' => true,
        'uploadUrl' => Url::to(['/ajax/clientuploadfile/', 'id' => $model->id]),
        'uploadExtraData' => [
      'user_id' => $model->id,
    ],
        'initialPreview' => $files->initialPreview($model->id),
        'initialPreviewConfig' => $files->initialPreviewConfig($model->id, Url::to(['/ajax/clientdeletefile/', 'user_id' => $model->id])),
    	'overwriteInitial'=>true,
    	'maxFileCount' => 10,
    	'fileActionSettings' => [
      'showZoom' => false,
      'showDrag' => false,
    ],
    ],
]);
} else{

}

public function initialPreviewConfig($id, $urlDel) {
      $return_json = [];
      foreach ($this->getAll($id)->getModels() as $k => $file) {
            $return_json[] = [
                'caption' => $file->file_name,//$_SERVER['DOCUMENT_ROOT'] . '/web/uploads/docs/'.$id.'/' . $file->file_name,
                'size' => filesize($_SERVER['DOCUMENT_ROOT'] . '/web/uploads/docs/'.$id.'/' . $file->file_name),
                'url' => $urlDel,
                'key' => $file->id,
            ];
        }
      return $return_json;
    }

Gives an error
e388836e445a45949ee2a3e327c33626.png
https://www.awesomescreenshot.com/image/2557890/44...
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-06-06
@webinar

First, check if the file exists, or wrap inif(file_exists($path_to_file))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question