Problem uploading Laravel / Intervention image

1

I have a problem when I try to upload an image, well, when I submit on form it returns the following error:

Intervention\Image\Exception\NotWritableException
Can't write image data to path (public/images/products/2014-06-01-16:24:38-581165_571926502843010_889453779_n.jpg)

Well, I figured it might be a permission problem, I went there and gave permission on the directory, but the darned continues to make the same mistake. Here is my code:

public function postCreate(){
            $validator = Validator::make(Input::all(),Product::$rules);

            if($validator->passes()){
                    $product = new Product();
                    $product->category_id   = Input::get('category_id');
                    $product->title                 = Input::get('title');
                    $product->description   = Input::get('description');
                    $product->price                 = Input::get('price');
                    $product->availability  = Input::get('availability');

                    $image = Input::file('image');
                    $filename = date('Y-m-d-H:i:s').'-'.$image->getClientOriginalName();
                    Image::make($image->getRealPath())->resize('468,249')->save('public/images/products/'.$filename);
                    $product->image                 = 'images/products/'.$filename;
                    $product->save();

                    return Redirect::to('admin/products/index')
                            ->with('message','Produto cadastrado');
            }
}
    
asked by anonymous 01.06.2014 / 19:20

3 answers

1

Thank you for all the answers, however, I resolved as follows:

$filename = date('Y-m-d-H-i-s').'.'.Input::file('image')->getClientOriginalExtension();
Image::make(Input::file('image')->getRealPath())->resize('468,249')->save( public_path('img/products/'.$filename));

I provided the absolute path of the file, not the relatio, from the root of the project. With this he uploaded, the solution was given in a question I asked in the Laravel Brasil group.

Question in the Laravel Brasil group

Thank you very much for your help!

    
02.06.2014 / 01:26
0

I'm not knowledgeable about Laravel, but I suggest a change to the file name.

Not if what S.O. is using but I suggest removing the ":" character from your file name, since in Windows and Linux it is an invalid character. See the documentation for Windows and a recommendation on this site . Change ": by " _ " or any other valid character and see the result.

Adapting the following line:

$filename = date('Y-m-d-H_i_s').'-'.$image->getClientOriginalName();
    
01.06.2014 / 19:36
0

Try this:

public function postCreate(){
    $validator = Validator::make(Input::all(),Product::$rules);

    if($validator->passes()){
            $product = new Product();
            $product->category_id   = Input::get('category_id');
            $product->title         = Input::get('title');
            $product->description   = Input::get('description');
            $product->price         = Input::get('price');
            $product->availability  = Input::get('availability');

            $image = Input::file('image');
            $filename = date('Y-m-d-H:i:s').'-'.$image->getClientOriginalName();
            Image::make($image->getRealPath())->resize('468,249')->save('images/products/'.$filename);
            $product->image         = 'images/products/'.$filename;
            $product->save();

            return Redirect::to('admin/products/index')
                    ->with('message','Produto cadastrado');
    }
}

Because you put public in save and do not need it, so it is not a valid path. By default you do not need to set public that framework already recognizes such path

    
02.06.2014 / 00:57