简体   繁体   English

Laravel 5干预无法将图像数据写入路径

[英]Laravel 5 Intervention Can't write image data to path

Here is my Controller 这是我的控制器

public function store()
{ 
    $data = Request::all();

    $rules = [
                'password'   => 'required|confirmed|min:3',
                'avatar'     => 'required|image|mimes:jpeg,png,bmp',
                'email'      => 'required|email|unique:users',
                'first_name' => 'required',
                'last_name'  => 'required',
                'level'      => 'required'
            ];

    $validator = validator::make($data, $rules);

    if($validator->passes()){
        if(!file_exists(public_path("assets/uploads".date('/Y/m/d/').$data['avatar']->getClientOriginalName()))){
            $path = public_path("assets/uploads".date('/Y/m/d/').$data['avatar']->getClientOriginalName());
            Image::make($data['avatar']->getRealPath())->resize(200, 200)->save($path);
        }
    }
}

And Here is my error 这是我的错误

Can't write image data to path (/var/www/html/rnd/public/assets/uploads/2015/10/16/tes.jpg) 无法将图像数据写入路径(/var/www/html/rnd/public/assets/uploads/2015/10/16/tes.jpg)

There is no 2015 folder inside uploads folder, so it should create automatically if folder doesn't exists. uploads文件夹内没有2015文件夹,因此如果该文件夹不存在,则应自动创建。

Please correct whats wrong with my code? 请更正我的代码有什么问题吗?

Any help appreciated. 任何帮助表示赞赏。

Please make sure the folder you want to write to is exists with the correct owner www-data:www-data and correct permission, one more again keep in mind. 请确保您要写入的文件夹存在正确的所有者www-data:www-data并具有正确的权限,请记住另一点。

Image::make($data['avatar']->getRealPath())->resize(200, 200)->save($path);

The above code doesn't create folder automatically if folder doesn't exist as developer says here 如果文件夹不存在,则上述代码不会自动创建文件夹,如开发人员在此处所述

https://github.com/Intervention/image/issues/56 https://github.com/Intervention/image/issues/56

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM