我在编写函数时遇到问题。当我尝试更新文件图像时,出现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;
}
答案 0 :(得分:2)
尝试以下行
public function uploadImg(Request $request){
$request->file('featured_image')->getClientOriginalName();
}
或
$file = Input::file('featured_image');
$file->getClientOriginalExtension();
$file->getClientOriginalName();
或
Input::file('featured_image')->getClientOriginalExtension();
查看文档的this section。