0

I want to save uploaded file to '/home/user/images' folder.

Is there any way to do this?

My 1st try: controller

public function save(Request $request) {
     $file = $request->file('image');
     $file_name = $file->getClientOriginalName();
     $file_path = '/home/user/images';
     
     $file->move($file_path, $file_name);
}

/////////////////////

My 2nd try: filesystems.php

'disks' => [
..
'custom_folder' => [
     'driver' => 'local',
     'root'   => '/home/user/images',
 ],
...

controller

public function save(Request $request) {
     $file = $request->file('image');,
     $file_name = $file->getClientOriginalName();
     
     Storage::disk('custom_folder')->put($file_name, $file);
}

I'm sorry if there is anything I did wrong. I just started learning php and Laravel. For now, I save the files in the 'public / images' file path. I will use these files in multiple projects in the future. So I thought of such a method but could not reach the result.

1 Answer 1

1
if($request->hasFile('image')){
  $image = $request->image;
  $image_new_name = $image->getClientOriginalName();
  $image->move('storage/custom_folder/', $image_new_name);
}

"storage" folder can be found inside "public" folder; public/storage/custom_folder.

If you want it outside your server dir then create a symlink inside your project folder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.