Ruben Ruben - 2 years ago 185
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download