Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 upload image form

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

like image 747
Ruben Avatar asked May 19 '13 14:05

Ruben


People also ask

How we can upload image in laravel?

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.

Where to put images in Laravel?

Just put your Images in Public Directory (public/... folder or direct images). Public directory is by default rendered by laravel application.


1 Answers

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.

like image 176
Ryan Tablada Avatar answered Oct 14 '22 16:10

Ryan Tablada