如何将上传图像保留在Public / Storage中的post文件夹中

时间:2019-05-13 04:14:34

标签: php laravel

我正在尝试将上传的图像保存到public_html/storage/post/中。但现在这段代码对我不起作用,并上传到direct public_html/

 $image = $request->file('image');
        $slug = str_slug($request->title);
        if(isset($image))
        {
//            make unipue name for image
            $currentDate = Carbon::now()->toDateString();
            $imageName  = $slug.'-'.$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();

            if(!Storage::disk('public')->exists('post'))
            {
                Storage::disk('public')->makeDirectory('post');
            }

            $postImage = Image::make($image)->save($imageName);
            Storage::disk('public')->put('post/'.$imageName,$postImage);

        } else {
            $imageName = "default.png";
        }

1 个答案:

答案 0 :(得分:0)

问题已在config/filesystems.php公共根目录中修复为 'root' => public_path().'/../public_html/storage',