Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to a member function move() on array

Tags:

php

laravel

 $files = $request->file('file');
        foreach ($files as $file){
            $filename = time().'.'.$file->getClientOriginalExtension();

            $location = public_path('uploads/'.$filename);

            $request->file->move(public_path('/uploads'), end($filename));

            $filename_arr = [];
            array_push($filename_arr, $filename);
            $filename = json_encode($filename_arr);
            $upload->filename = $filename;
        }

I have checked several others codes online but they seem to be working fine but mine keeps saying that move cannot be used on an array

like image 530
Mbugua Njane Avatar asked Mar 01 '26 20:03

Mbugua Njane


1 Answers

You're using $request->file array instead of $file element of the array. So, change this:

$request->file->move(public_path('/uploads'), end($filename));

To:

$file->move(public_path('/uploads'), end($filename));
like image 172
Alexey Mezenin Avatar answered Mar 04 '26 10:03

Alexey Mezenin