How can I upload image using Storage::put on the laravel?
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?
put() is when you have the file contents held in a variable (not a pointer to the file)
Storage::put($fileName, $file);
I know this question is old, but for future people that come across this, use the following
Storage::put($fileName, File::get($request->file));
where $request->file is the file uploaded by a user. This will create the file within the default Storage location with the specified file name.
@natew WHAT, load the whole file into memory to then write it back to a file?
Why do that when there is a perfectly good move() operation
So is this a good approach?
public function store(Request $request) {
Storage::put("uploads", $request->get("file"));
}
Please or to participate in this conversation.