I have an application in L8, I configured a disk to use it in the Storage;
'avatars' => [
'driver' => 'local',
'root' => storage_path('app/private/images/avatars'),
],
Then I created the corresponding link
'links' => [
public_path('avatars') => storage_path('app/private/images/avatars'),
],
Then in my controller I save the file to Storage;
public function cambiarAvatar(Request $request)
{
$path = Storage::disk('avatars')->put('imagen.jpg',$request->file('avatar'));
return $path;
}
The drawback with this code is that it creates a directory called image.jpg, that is, app/private/images/avatars/something.jpg/... and the name of the file once uploaded is temporary;
Could you tell me what I may be doing wrong? I need to be able to save a file with the name that I indicate, in the directory established on the disk, that is, in app/private/images/avatars.
Many thanks in advance.
I think your problem comes from how you pass the second parameter to the method
put()
since this should be the raw content of the file, as it says here in its documentation:And you are passing him the complete file. So you should do something like this:
Using PHP 's file_get_contents() function . Although it would be much easier for you to use the Laravel method like this:
storeAs()