Использую вот этот image uploader:
https://github.com/perminder-klair/yii2-dropzone
Настройки расширения :
echo \kato\DropZone::widget([
'options' => [
'maxFilesize' => '1',
'uploadMultiple' => true,
'url' => '/admin/works/upload',
'addRemoveLinks' => true,
],
'clientEvents' => [
'complete' => "function(data){console.log(data)}"
],
]);
Метод :
public function actionUpload()
{
$file = UploadedFile::getInstanceByName('file');
$file->saveAs($_SERVER['DOCUMENT_ROOT'] . '/frontend/web/uploads/works/' . $file->baseName . '.' . $file->extension);
return true;
}
Ошибка в консоли :
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
<pre>PHP Fatal Error 'yii\base\ErrorException' with message 'Call to a member function saveAs() on null' ↵↵in /home/alexander/My_projects/spa.local/backend/controllers/WorksController.php:67↵↵Stack trace:↵#0 [internal function]: yii\base\ErrorHandler->handleFatalError()↵#1 {main}</pre>"
ошибка понятна $file - пустая , но по умалчанию как сказанно "paramName = default file".
www.dropzonejs.com/#configuration-options