Member function call getClientOriginalName () on an object without an object

I try to make an image downloader, but it always gives 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); if(Input::hasFile('image')){ $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"> <label>Poster</label> <input class="" type="file" name="image"><br/> <input class="btn btn-primary" type="submit" > </form> 

what is wrong with my code?

+6
source share
3 answers

You are missing the enctype attribute in your form markup.

Or do it

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

or that...

 {{ Form::open(array('url' => 'user/poster/upload_process', 'files' => true, 'method' => 'post')) }} // ... {{ Form::close() }} 
+19
source

This code is correct, but you did not check the return values โ€‹โ€‹of Input::file('image') . I think the return value may not be correct, or your class. The input does not have the name of the public function getClientOriginalName .

code:

 $file = Input::file('image'); var_dump($file); // if return a correct object. you will check your class Input. 

Good luck.

0
source

Please check your form 'files' => true {!! Form :: open (['route' => ['Please Type Url'], 'class' => 'form-horizontal', 'files' => true ])}

0
source

Source: https://habr.com/ru/post/958287/


All Articles