Thursday, March 9, 2017

Laravel 5 File Uploading getClientOriginalExtention does not exist error

when i`m developing file uploading using laravel 5.4 it gives this error.

Method getClientOriginalExtention does not exist.

Here is my UploadController.

    public function insertFile(){
        $filetitle=Input::get('file_title');
        $file=Input::file('filenam');
    $rules = array(
   'file_title' => 'required',
    'filenam' => 'required|max:20000|mimes:doc,docx,pdf,jpg,png,jpeg'
            );

        $validator = validator::make(Input::all(), $rules);

        if($validator -> fails()){
            $messages=$validator -> messages();
            return Redirect::to('upload')->withInput()->withErrors($validator);

        }
        else if($validator -> passes()){
            if(Input::file('filenam')->isValid()){
                $extention=Input::file('filenam')->getClientOriginalExtention();
                $filename=rand(11111,99999).'.'.$extention;

                $destinationPath='up_file';
                $file->move($destinationPath, $filename);

                $notification = array(
                    'message' => 'File Uploaded Successfully',
                    'alert-type' => 'success'
                    );

                return Redirect::to('upload')->with($notification);
            }
            else{
                $notification = array(
                    'message' => 'File is not Valid!',
                    'alert-type' => 'error'
                    );

                return Redirect::to('upload')->with($notification);
            }
        }
    }

can anyone help me to solve this. thank you very much



via Dasun

Advertisement