Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't write image data to path in laravel

Tags:

laravel-4

I am having the same error as this guy is :

Another thread

basically the error i have is uploading the image to the specific path, my code is as follows :

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');


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

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

    return Redirect::to('admin/products/index')->with('message' , 'something went wrong')
                ->withErrors($validator)->withInput();

} 

I was just trying to follow a tutorial on laravel e-commerce web application.

I guess the problem is that i don't have write permisson in my directory , how do i add write permission in my directory. I.E. the public folder, I googled a few places , but i don't understand what is it that i have to edit ?

I.E the htaccesss file or can i make write changes on the cmd ? also how do i check what weather a directory is write protected .

PS. i am using windows . i am attaching a screenshot of the error .

error

Thank you.

like image 870
Alexander Solonik Avatar asked Jan 08 '23 15:01

Alexander Solonik


1 Answers

You might want to change the dateformat since windows doesn't allow colons in filenames:

$filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();

And you also might want to add a trailing slash to your path so it doesn't concatenate the filename to the folder path:

Image::make($image->getRealPath())->resize(468, 249)->save('public/img/products'.$filename);

like image 125
VF_ Avatar answered Jan 30 '23 20:01

VF_