[[+content_image]]
A
A
alex4answ2019-02-23 20:36:01
Yii
alex4answ, 2019-02-23 20:36:01

How to upload and process files without ActiveForm?

Good evening, I encountered the following problem:
1. I am uploading a file via ajax, but according to the classical scheme:

в моделе:
public $image;
..
rules:
[['image'], 'file', 'extensions' => 'png, jpg']

in the controller where ajax goes:
$data = \Yii::$app->request->post();
$model->attributes = $data; // не load потому что у меня не activeForm и не вложенный массив post

$model->validate -> error "image cannot be blank"

I don’t quite understand how yii models work with files, I read the documentation, I didn’t really find anything, apparently I was looking in the wrong place.
But still, how to properly organize the work of yii with files?
$_FILES['image'] - displays file information normally.
I can not understand, please tell me how to work in such cases?
I'm not sure that I can just take and start working with _FILES, I think there should be something about this.
I would be very grateful for a hint

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
P
padlyuck, 2019-02-23
@padlyuck

UploadedFile::getInstanceByName('image'); get your file. And then according to the instructions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question