I'm trying to make a form that allows uploading a file and store it in the public/upload folder of the application.
my form is:
<form action="/image/save" method="post">
<input name="image" type="file" />
<input type="submit" value="Save"/>
</form>
and the controller:
public function save(){
$file = Input::file('image');
$destinationPath = 'upload/';
$filename = $file->getClientOriginalName();
Input::file('image')->move($destinationPath, $filename);
But when I run it I get the following error:
Call to a member function getClientOriginalName()
on a non-object
blade. php and update the file with code below. Now if you go to browser and visit /image-upload you will see the image upload option. and once you select and image and upload it you will see the success message with image.
Just put your Images in Public Directory (public/... folder or direct images). Public directory is by default rendered by laravel application.
You need to have a file input enabled on a form. (Doc)
In Laravel, you can use:
Form::open('image/save', array('files'=> true))
or
<form action="/images/save" method="post" enctype="multipart/form-data">
Otherwise all you are receiving from the file input is the file name as a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With