1

I'm having issues writing a function. When I try to update the file image, I get the error in getClientOriginalName().

Call to a member function getClientOriginalName() on array

<?php

/**
 * Upload File.
 *
 * @param array $input
 * @return array $input
 */
public function uploadImg($input)
{
    if (isset($input['featured_image']) && !empty($input['featured_image'])) {
        $avatar = $input['featured_image'];
        $fileName = time() . $avatar->getClientOriginalName();
        $this->storage->put($this->upload_path . $fileName, file_get_contents($avatar->getRealPath()));
        $path = 'posts_images/' . $fileName;
        $input = array_merge($input, ['featured_image' => $path]);
    } elseif (isset($input['img']) && !empty($input['img'])) {
        $avatar = $input['img'];
        $fileName = time() . $avatar->getClientOriginalName();
        $this->storage->put($this->upload_path . $fileName, file_get_contents($avatar->getRealPath()));
        $path = 'posts_images/' . $fileName;
        $input = array_merge($input, ['img' => $path]);
    }

    return $input;
}
Karl Hill
  • 12,937
  • 5
  • 58
  • 95

1 Answers1

2

Try below lines

public function uploadImg(Request $request){

  $request->file('featured_image')->getClientOriginalName();
}

or

$file = Input::file('featured_image');
$file->getClientOriginalExtension(); 
$file->getClientOriginalName();

or

Input::file('featured_image')->getClientOriginalExtension();

Check this section of the documentation.

Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
sadaiMudiNaadhar
  • 354
  • 1
  • 12