0

My code to upload image like this :

$file = $file->move($path, $fileName);

The code works

But I want to change it using Storage::put like this reference :

https://laravel.com/docs/5.6/filesystem#storing-files

I try like this :

Storage::put($fileName, $path);

It does not works

I'm confused, where I must put $file on the code

How can I solve this problem?

Update :

$file = file of image
$path = storage_path('/app/public/product/')
$fileName = chelsea.jpg

So I want to save the file with name chelsea.jpg on the /app/public/product/

1 Answer 1

2

Easy Method

$path = $request->file('avatar')->storeAs(
'avatars', $request->user()->id
);

This will automatically store the files in your default configuration.

This is another example

Storage::put($fileName, $path);

Hope this helps

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

3 Comments

I want to using this : Storage::put($fileName, $file->getRealPath());. But How can I set the path? I want to save the image this : $path = storage_path('/app/public/product/');
@SuccessMan laravel do this for you by default. It will be saved in storage/app/public/yourfolder
Great. Thanks for your help

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.