【问题标题】:file_put_contents(...): failed to open stream: Is a directoryfile_put_contents(...): 无法打开流: 是一个目录
【发布时间】:2018-02-12 18:17:42
【问题描述】:

我有上传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/ 目录,但失败了。

错误:

    (1/1) ErrorException
file_put_contents(/home/artem/PhpstormProjects/thefeedfeed-api/storage/app/public/images): failed to open stream: Is a directory

【问题讨论】:

  • 我认为你的目录有权限问题!!你能指出你的确切错误吗
  • 更新帖子并添加错误
  • 更新帖子并添加错误 - @katedega 但这是你的问题吗? :O
  • @Script47 - 我在帖子中有错误。我做错了什么?或者如何将文件保存到我需要的目录?
  • @katedega 请检查这个 =>> stackoverflow.com/questions/14560658/…

标签: php laravel laravel-5 php-7


【解决方案1】:

线

Storage::disk('public')->put('images/',$fullName, $decode);

应该是

Storage::disk('public')->put('images/'.$fullName, $decode);

您提供了三个参数 - 目录、文件名和内容。这个方法应该有两个参数,完整的文件路径(即目录和文件名)和内容。您需要连接前两个参数 - 只需将 , 更改为 .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-11
    • 2015-05-05
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    相关资源
    最近更新 更多