我在Yii2中使用perminder-klair/yii2-dropzone
wedgit在文件夹和数据库中上传多个文件。但是我遇到问题,文件没有保存在数据库中,而是保存在文件夹中。如何在数据库中保存文件?
在视图中: -
echo \kato\DropZone::widget([
'options' => [
'url' => 'index.php?r=employee-tab/upload',
'maxFilesize' => '2',
],
'clientEvents' => [
'complete' => "function(file){console.log(file)}",
'removedfile' => "function(file){alert(file.name + ' is removed')}"
],
]);
控制器中的: -
public function actionCreate()
{
$model = new EmployeeTab();
$fileName = 'file';
$uploadPath = 'uploads';
if (isset($_FILES[$fileName])) {
$file = \yii\web\UploadedFile::getInstanceByName($fileName);
//Print file data
//print_r($file);
if ($file->saveAs($uploadPath . '/' . $file->name)) {
//Now save file data to database
echo \yii\helpers\Json::encode($file);
}
}
else{
return $this->render('create', [
'model' => $model, ]);
}
return false;
}