Spadaboyz Spadaboyz - 1 year ago 126
PHP Question

Call to a member function getClientOriginalName() on a non-object

I'm trying to make an image uploader, but it always give me this error

Call to a member function getClientOriginalName() on a non-object

here is my code controller code

public function uploadImageProcess(){

$destinatonPath = '';
$filename = '';

$file = Input::file('image');
$destinationPath = public_path().'/assets/images/';
$filename = str_random(6).'_'.$file->getClientOriginalName();
$uploadSuccess = $file->move($destinationPath, $filename);

$images = new Images;

$images->title = Input::get('title');
$images->path = '/assets/images/' . $filename;
$image->user_id = Auth::user()->id;

Session::flash('success_insert','<strong>Upload success</strong>');
return Redirect::to('user/dashboard');

and here is the upload form

<form role="form" action="{{URL::to('user/poster/upload_process')}}" method="post">
<label>Judul Poster</label>
<input class="form-control" type="text" name="title">
<input class="" type="file" name="image"><br/>
<input class="btn btn-primary" type="submit" >

what's wrong with my code?

Answer Source

You miss enctype attribute in your form markup.

Either do this

<form role="form" action="{{URL::to('user/poster/upload_process')}}" method="post" enctype="multipart/form-data">

or this...

{{ Form::open(array('url' => 'user/poster/upload_process', 'files' => true, 'method' => 'post')) }}
// ...
{{ Form::close() }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download