在非对象上调用成员函数getClientOriginalName()

Spa*_*oyz 9 php upload object laravel laravel-4

我正在尝试制作图片上传器,但它总是给我这个错误

Call to a member function getClientOriginalName() on a non-object
Run Code Online (Sandbox Code Playgroud)

这是我的代码控制器代码

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');
    }
}
Run Code Online (Sandbox Code Playgroud)

这是上传表格

<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>
Run Code Online (Sandbox Code Playgroud)

我的代码出了什么问题?

And*_*yco 23

您错过enctype了表单标记中的属性.

要么这样做

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

或这个...

{{ Form::open(array('url' => 'user/poster/upload_process', 'files' => true, 'method' => 'post')) }}
// ...
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)