user7986752
user7986752

Reputation:

Laravel 5.4 Upload images with their own names

i want to upload my images with their own names. But when i tried, they upload with diffrent names. for example; php0K0Saj.57352.JPG (!?)

my controller;

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');
    }

Upvotes: 2

Views: 165

Answers (1)

Oluwaseye
Oluwaseye

Reputation: 695

Update the line.

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

With

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

Hope this helps

Upvotes: 1

Related Questions