Answer the question
In order to leave comments, you need to log in
How to fix Ajax image upload error (Dropzone.Js)?
I am using this image uploader: https://github.com/perminder-klair/yii2-dropzone
Extension settings:
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>"
Answer the question
In order to leave comments, you need to log in
var_dump($_FILES);
$file = UploadedFile::getInstanceByName('file');
File upload indicated in the form?
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question