1

我在编写函数时遇到问题。当我尝试更新文件图像时,出现错误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;
}
4

1 回答 1

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();

检查文档的这一部分

于 2018-11-27T16:47:09.837 回答