get file name without extension in laravel?

前端 未结 13 943
温柔的废话
温柔的废话 2021-02-05 01:14

I have used Input::file(\'upfile\')->getClientOriginalName() to retrieve name of uploaded file but gives name with extension like qwe.jpg.How do I g

13条回答
  •  忘了有多久
    2021-02-05 02:06

    You can use this code too.

        if ($request->hasfile('filename')) {
            $image = $request->filename;
            $namewithextension = $image->getClientOriginalName(); //Name with extension 'filename.jpg'
            $name = explode('.', $namewithextension)[0]; // Filename 'filename'
            $extension = $image->getClientOriginalExtension(); //Extension 'jpg'
            $uploadname = time() . '.' . $extension;
            $image->move(public_path() . '/uploads/', $uploadname);
        }
    

提交回复
热议问题