Laravel 5 path not writable.Using the Intervention/Image Class

416 Views Asked by At

This is my first question here,yay :) or maybe not so much :( . Anyway am getting the error below when i try to save my image instantiation in Laravel5 . The path exists and is writable, i have gone through the code over and over. Help :( . I am on windows 8.1 running wampserver.

Can't write image data to path (F:\wamp\www\pinkworld\public/images/products/2015-06-08-05:51:14-IMG_8224.JPG)

This what my code for that controller looks like

 use App\Product;
 use App\Http\Requests;
 use App\Http\Controllers\Controller;
 use App\Category;
 use Carbon\Carbon;
 use App\Http\Requests\ProductRequest;
 use Image;


class ProductsController extends Controller {

    /**
    *
    *Protect our post request
    *
    *
    *
    */
    public function __construct(){
        //$this->beforeFilter(crsf, array('on' => 'post'));
    }


    /**
    *
    *Show all products
    *
    *@return Response
    *
    */
    public function index(){
        $categories = array();

        foreach(Category::all() as $category){
            $categories[$category->id] = $category->name;
        }
        $products= Product::all();
        return view('products.index',compact('products','categories'));
    }

    /**
    *
    *Shows form for creating a single form
    *
    *@return Response
    *
    */

    public function create(){

    return view('products.index');

    }

    public function store(ProductRequest $request)
    {   
        //inserting product values          
        $product= new Product();
        $product->category_id = $request['category_id'];
        $product->title =  $request['title'];
        $product->description =  $request['description'];
        $product->price =  $request['price'];

        //Using Request::file the file that didnt pass through the request file for validation
        //Using $request->file('filename') gets me the file after it has been validated
        //

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


        $product->save();
        \Session::flash('message','Product Created');
        return redirect('admin/products');  
    }




    /**
    *
    *Show single product
    *
    *param interger $id
    *
    *@return Response
    *
    */

    public function show($id){

        $product = Product::findOrFail($id);


        return view('admin/products',compact('product')); //$contact->title
    }

    /**
    *
    *Delete single product
    *
    *param interger $id
    *
    *@return Response
    *
    */

    public function destroy($id){
        File::delete('public/'.$product->image);
        $product= Product::find(Request::get('id'));
        \Session::flash('message','Product Deleted');
        if ($product){
            $product->delete();
        }

        return redirect('admin/products');

    }

    public function postToggleAvailability(){
        $product= Product::find( $request->get('id'));
        if ($product){
            $product->availability = $request['availability'];
            $product->save();

            \Session::flash('message','Product Updated');
            return redirect('admin/products');          
        }
        \Session::flash('message','Invalid Product');
        return redirect('admin/products');
    }


    /**public function edit($id)
    {

        $contact = Contact::findOrFail($id);

        return view('contacts.edit',compact('contact'));

    }**/

    public function update($id, productRequest $request)
    {

        $product = Product::findOrFail($id);

        $product->update($request->all());

        return redirect('products');

    }
}
1

There are 1 best solutions below

0
On

Oh i figured it out,windows didn't like prepending the $filename with the date function. Forgot about filenaming rules in windows. Hope this helps some too,so i wont delete it.