我在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);}
}
我尝试将图像保存到public / image /目录,但失败了。
ERROR:
(1/1) ErrorException
file_put_contents(/home/artem/PhpstormProjects/thefeedfeed-api/storage/app/public/images): failed to open stream: Is a directory
答案 0 :(得分:1)
该行
Storage::disk('public')->put('images/',$fullName, $decode);
应该是
Storage::disk('public')->put('images/'.$fullName, $decode);
您提供了三个参数 - 目录,文件名和内容。此方法应采用两个参数,完整文件路径(即目录和文件名)和内容。您需要连接前两个参数 - 只需将,
更改为.