Answer the question
In order to leave comments, you need to log in
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;
}
Answer the question
In order to leave comments, you need to log in
First, check if the file exists, or wrap inif(file_exists($path_to_file))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question