Laravel 5.4使用自己的名称上传图像

时间:2017-07-27 21:07:28

标签: php laravel-5.4

我想用自己的名字上传我的图片。但是当我尝试时,他们上传了不同的名字。例如; php0K0Saj.57352.JPG(!?)

我的控制员;

public function post_Savenews(Request $request)
    {
        $request->all();
            /* out of question
        $head = $request->input('head');
        $content = $request->input('content');
        $keywords = $request->input('keywords'); */

        $featured=$request->post_featured;
        $extension=$request->post_featured->getClientOriginalExtension();

        $photoName = $featured . '.' . rand(11111, 99999) . '.' . $extension;
        $request->post_featured->move(public_path('uploads'), $photoName);
        News::create(array('head' => $head, 'content' => $content, 'keywords' => $keywords,'post_featured'=>$photoName));

        return redirect()->route('index');
    }

1 个答案:

答案 0 :(得分:1)

更新该行。

$photoName = $featured . '.' . rand(11111, 99999) . '.' . $extension;

使用

$photoName = $request->post_featured->getClientOriginalName();

希望这有帮助