0

I am new to Laravel 5. Actually I'm using Laravel Framework version 5.1.16. When uploading an image, it is uploading and saved in database table, but it is not moved to a specified folder.

Any help would be appreciated.

This is my controller code:

public function addexpense(Request $request) {

  $inputs=Input::all();
  $validation = Validator::make($inputs, Expense::$rules);

  if($validation->fails()) {
    return Redirect::to('expenseaddform')->withErrors($validation)->withInput();
  }else{
    $input=Input::only('id','expense_date','expense_category_id','vendor_id','customer_id','amount','tax1_id','tax2_id','note','receipt');   

    $data->expense_date = $input['expense_date'];
    $data->expense_category_id = $input['expense_category_id'];
    $data->vendor_id = $input['vendor_id'];
    $data->customer_id = $input['customer_id'];
    $data->amount = $input['amount'];
    $data->tax1_id = $input['tax1_id'];
    $data->tax2_id = $input['tax2_id'];
    $data->note = $input['note'];

    $image = Input::file('receipt');
    $filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
    Image::make($image->getRealPath())->resize(468, 249)->save('public/uploas/'. $filename);
    $data->receipt = $input['image'];

    $data->save();

    return redirect('expenseinfo');
  }
}

Form code:

<form action="addexpense" enctype="multipart/form-data" >
    Receipt:</td><td><input type="file" name="receipt"value="{{Input::old('receipt')}}">
    <input style="margin-left:30px"type="submit" value="Add" name="submit"> 
</form> 
sandy
  • 25
  • 1
  • 8

2 Answers2

1

You are doing it wrong with Image::make() function. Try the following:

Image::make($image->getRealPath())->resize(468, 249)->save(public_path() . '/uploads/' . $filename);
Mustafa Ehsan Alokozay
  • 5,583
  • 2
  • 24
  • 30
-1

Try this:

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

For more information you can check the below link: https://youtu.be/F92JpVWhDw4