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

adhik13th's avatar

How to save image to directory in shared hosting laravel ?

I have a function to upload files. on Localhost it's not having an error. but after I deploy on shared hosting, its have a problem. If localhost, I'm not moving some folder, but on "tutorial" shared hosting, I need to make 2 folders. Laravel and public. this Laravel folder is all file on project Laravel without public

It's my schema on my shared hosting

(/home/sippausr)

etc

Laravel ->

  • app

  • bootstrap

  • config

  • database

  • public_html

    • files ( this file saved here)
  • resources

  • routes

  • storage

  • tests

  • vendor

logs

mail

public_ftp

public_html ->

  • css

  • files (not on here, i need to save here)

  • home

  • images

  • js

  • kalibrasi

  • public

  • sop

  • theme

And I have a function to upload a file and saved this file to directory files on public_html 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');
}

But, this file not saved at public_html/files,

This file saved in the Laravel folder, on public_html( you can see at schema). Can someone help me?

0 likes
6 replies
adhik13th's avatar

i think its not solution , can someone suggest me to changing this line

 $file->move(public_path().'/files/', $name);  

i think public_path is the problem

Tray2's avatar

Normally the file is stored in the storage directory.

adhik13th's avatar

ok , now if my file in storage dir , how i can showing at views ? normally i use like this

  <img src="{{ asset('files/' . $data->image) }}" alt="">

and i think its wrong ,

adhik13th's avatar

ok , i have symlink and my image saved at storage , i have problem to showing on view

Please or to participate in this conversation.