here is controller code :-
$gallery = $this->Galleries->newEntity($this->request->getData());
$uploaded_path = “/img/uploads/”;
$tmp_name = $this->request->data[‘file’][‘tmp_name’]; // this line got an error saying Undefined index: file
If i print the following code then get all the data as per array format $form_data = $this->request->getData();
but i getData though the following line get $image_name = $this->request->data['file']['name'];
Accessing routing parameters through getData will removed in 4.0.0. Use getParam() instead.
Undefined index means there is no tmp_name, which tells me that file isn’t uploaded correctly.
Quite possibly, the form enctype is set differently.
Need more code to help you.
If you want to adhere to MVC style uploads then change request object through behaviours. For example, if there a column which stores user’s avatar file path on webroot and if you are doing something like
psuedo-code below:
move uploaded file > dest
$this->request->data[<field>] = <path of dest>
$modelEntityCollection->save($this->request->data)
What often seems to happen is that someone sees there’s software that does most of what they want, but instead of adding what it’s missing, they write their own, but leaving out the stuff they don’t need. And then someone else does the same, and someone else, and the projects all wither and die because there’s not enough people using any of them.