Tuesday, June 27, 2017

how to upload image in laravel


in main function

if (Input::hasFile('image'))
{
  $getUpload = $this->uploadFile($imageNameWanted);
  if($getUpload){
  $UpdateProductImage = PackProduct::find($productId)->update(array('image' =>$imageNameWanted));
  }
  else {
  return Redirect::back()->withErrors('Wrong format of image file')->withInput();;
  }
}



use this function in main function
public function uploadFile($imageNameWanted)
{
        $destinationPath=base_path().'/public/awesome-assets/img/pdfs/';
$uploadResult = Input::file('image')->move($destinationPath,$imageNameWanted);
if($uploadResult)
{
return true;
}
else {
  return false;
}
}

No comments:

Post a Comment