Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shiva's avatar
Level 5

Call to a member function getClientOriginalName() on null

I'm creating a form that uses dropzone.js, but I'm trying to save the filename to my database. When I submit I get this error

Call to a member function getClientOriginalName() on null

This is my function

public function imageTest(){
            $menu = new Menu;
            $input = Input::all();
            $file = Input::file('file');
            
            $destinationPath = 'menu_images';
            $filename = $file->getClientOriginalName();
            $upload_success = Input::file('file')->move($destinationPath, $filename);

            echo "<PRE>";
            print_r($filename);
            die();
        }
0 likes
13 replies
goatshark's avatar

@shiva You might want to verify that your "file" is not being sent as an array of files. Especially when using dropzone, I've found often that what I initially expect to be able to use $file for, I actually need to use $file[0] for. Maybe dd'ing Input::file('file) would be a good place to start so you can see what you're working with.

Shiva's avatar
Level 5

@goatshark - when I dd Input::file('file') I get null. I also noticed that for some reason the <input type='file'> for dropzone is at the bottom of the page and not in the form.

vipin93's avatar

have u add in ur form" enctype="multipart/form-data" " and also try to change

 $file = Input::file('file'); to $file = $request->file ;
3 likes
Shiva's avatar
Level 5

@vipin93 - Here is my form

{{ Form::open(array('route' => 'menus.imageTest', 'files' => true, 'enctype' => 'multipart/form-data', 'class' => 'add-form dropzone', 'id' => 'my-awesome-dropzone')) }}
        <div class="form">
            <div class="parents_input">
                <div>
                    {{ Form::label('menu_id', 'Parent Menu')}}
                </div>
                <div>
                    {!! Form::select('menu_id', $menu_id->prepend('Please Select', '0'), null, array("class" => "form-control")) !!}
                </div>
            </div>

            <div class="title_input">
                <div>
                    {{ Form::label('title', 'Title') }}
                </div>
                <div>
                    {{ Form::text('title','', array('id' => 'title', "class" => "form-control")) }}
                </div>
            </div>

            <div class="dropzone-previews"></div> <!-- DROPZONE PREVIEW -->

            <div class="layout_type">
                <input id="home" type="radio" value="home" name="type">
                <label for="home">Home</label>
                <input id="stories" type="radio" value="stories" name="type">
                <label for="stories">Stories</label>
            </div>
            <div class="submit_button">
                <div>
                    {{ Form::submit('Submit', array("class" => "btn btn-info submit", "role" => "button")) }}
                </div>
            </div>
        </div>
    {{ Form::close() }}
Snapey's avatar

The point about drop zone is that its meant to upload files in the background (via ajax) and not part of a form submission.

I think you can somehow make it work by not having it process its queue but I can't just see how to do that.

Shiva's avatar
Level 5

@vipin93 - can you prehaps give me the name of the video. I'm having a problem loading it

Shiva's avatar
Level 5

@vipin93 - That video helped. Now all I need to do is make it work on submit instead of automatically.

Faks's avatar

simple to fix :)

public function imageTest() { $menu = new Menu; $input = Input::all(); if (Input::hasFile('file')) { $file = Input::file('file');

        $destinationPath = 'menu_images';
        $filename = $file->getClientOriginalName();

$upload_success = Input::file('file')->move($destinationPath, $filename); }

}

this how you get rid of that error.

Please or to participate in this conversation.