Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adhik13th's avatar

Upload Image not saved at directory on server Laravel 5.8

I deploy my website , and i have a bug on my upload image , this image cant saved at directory

my directory is in

in public_html on folder named files

on localhost its not having problem but after i deploy this , i have it .

my Controller on my localhost (not have problem like this)

 public function store6(Request $request)
{
    $this->validate($request, [
        

    ]);

    if($request->hasfile('image'))
     

        
        {   $file = $request->file('image');
            $name=$file->getClientOriginalName();
            $file->move(public_path().'/files/', $name);  
            $data = $name;  
        }
    

    $user = new pemeliharaan;
    $id = Auth::user()->id;

    $user->user_id = $id;
    $user->alat_id = $request->alat_id;
    $user->pertanyaan =json_encode($request->except
    (['_token','name','alat_id','status','catatan','image']));
    $user->catatan = $request->catatan;
    $user->image=$data;
    $user->status = $request->status;


    $user->save();
  // dd($user);
    return redirect('user/show6')->with('success', 'Data Telah Terinput');

}

this image "name" saved on DB but this file not saved , cant someone correct my code ?

0 likes
14 replies
lide's avatar

Use store, not move. You can't move before stored once.

$file->store()

Snapey's avatar

move is the correct operation

most lilkely issue is no rights to create files in public folder

Jaikangam's avatar

@SNAPEY - I am having the same problem. Upload image error say Can't write image data to path this seem to be permission problem how to solve it.

munazzil's avatar

You have simply use as like below because you haven't assign the data to image ,

  {   $file = $request->file('image');
        $name=$file->getClientOriginalName();
        $file->move(public_path().'/files/', $name);  
        $data['image'] = $name;  
    }

and you haven't save the data and top of your controller use use App\User;

User::create($data);
Snapey's avatar

@munazzil

are you answering the same question or a different one?

Your answers get more crazy

adhik13th's avatar

@MUNAZZIL - No sir , in my local its work and saved this data to directory an database . i think this problem is "how to save this file to directory"

1 like
adhik13th's avatar

@SNAPEY - in shared hosting laravel we save the file in public_html . its right ?

Snapey's avatar

Only if you have created such a directory, and your webserver has permissions to write there

Please or to participate in this conversation.