我在编写函数时遇到问题。当我尝试更新文件图像时,出现错误getClientOriginalName().
调用数组上的成员函数 getClientOriginalName()
<?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;
}