Ruben Ruben - 10 months ago 80
PHP Question

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"/>

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
on a non-object


You need to have a file input enabled on a form. (Doc)

In Laravel, you can use:

Form::open('image/save', array('files'=> true))


<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.