Reputation: 13
I have fuction for upload image in base64:
public function upload(UploadImageRequest $request) {
$data = (\Request::input('image'));
$decode = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
$info = @getimagesizefromstring($decode);
$extn = image_type_to_extension($info[2]);
if ($extn ==".png"){
$fullName = md5(time().uniqid()).$extn;
Storage::disk('public')->put('images/',$fullName, $decode);
$image = Image::make();
$image->url = Storage::url($fullName);
$image->saveOrFail();
return Response::json($image, ResponseHttp::HTTP_CREATED);
}
else {dd(1);}
}
I try to save my image to public/image/ directory, but failed.
ERROR:
(1/1) ErrorException
file_put_contents(/home/artem/PhpstormProjects/thefeedfeed-api/storage/app/public/images): failed to open stream: Is a directory
Upvotes: 1
Views: 6993
Reputation: 17433
The line
Storage::disk('public')->put('images/',$fullName, $decode);
should be
Storage::disk('public')->put('images/'.$fullName, $decode);
You're providing three arguments - the directory, the file name and the contents. This method should take two arguments, the full file path (i.e. directory and file name), and the contents. You need to concatenate the first two arguments - just change ,
to .
Upvotes: 1