Lalit's avatar
Level 1

Image Uploading getting error , i have a two days not understand how to solve this , I try everything but not working, For help Thanks in Advance

Call to a member function getClientOriginalExtension() on string

$test = $request->file('fileToUpload')->getClientOriginalExtension();

     echo $test; die('test');
0 likes
7 replies
cre3z's avatar

can you dump your $request and show us the output?

1 like
RamjithAp's avatar
Level 10

Make sure your upload form has files="true" or multipart header.

Lalit's avatar
Level 1

View <?php echo Form::open(array('url' => '/admin.employment_main','files'=>'true')); echo 'Select the file to upload.'; echo Form::file('fileToUpload');

     echo Form::submit('Upload File');
     echo Form::close();
  ?>  

Controller

public function uploadfile(Request $request) {

     $contract = EmployeeContract::create(request()->except(['_method', '_token']));


       
       if ($request->hasFile('fileToUpload')) 
       {

        echo "string";

         } else {
             
             echo "no";

         }

die();

    if (request()->hasFile('fileToUpload')) {
        $document->addMediaFromRequest('fileToUpload')->withCustomProperties(['is_default' => true])->employment_enrolment('documents');
    }

    // alert()->success('Document saved')->autoclose();   

}
Lalit's avatar
Level 1

$request->hasFile('fileToUpload') here was getting the error

Call to a member function hasFile() on string

RamjithAp's avatar

Why there is a dot in your url? Also true without single quotes. Try this

{{Form::open(array('url' => 'admin/employment_main', 'method' => 'post', 'files' => true))}}

Please or to participate in this conversation.