Answer the question
In order to leave comments, you need to log in
How to save an image to the server?
I can’t upload a photo to the server in any way, I did it according to various examples, the upload simply does not occur. Tell me what I'm doing wrong:
Model:
class UploadForm extends Model
{
public $imageFile;
public function rules()
{
return [
) ?>
<?= $form->field($model, 'imageFile')->fileInput() ?>
<button>Submit</button>
<?php ActiveForm::end() ?>
$this->imageFile->saveAs('uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
it does not find such a folder, I have the uploads folder right in the root, if this is the problem, then tell me how to set the path to it
Answer the question
In order to leave comments, you need to log in
It may be worth specifying the full path to save.
I usually create aliases to store files
'@picture' => '/uploaded/',
'@upload' => '@app/web/uploaded/',
$file = UploadedFile::getInstance($this, $code);
$filePath = time() . '_' . $file->baseName . '.' . $file->extension;
$file->saveAs('@upload/' . $filePath);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question