'"Path cannot be empty" laravel

I want to save a pdf file in the storage folder but when I insert a file in my form and I click on the button, it displays me the error "Path cannot be empty". However, the path is not empty. Here is my function that allows me to do this :

public function getFilenametostore(Request $request): string
{
    $filenamewithextension = $request->file('profile_pdf')->getClientOriginalName();

    $filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);

    //get file extension
    $extension = $request->file('profile_pdf')->getClientOriginalExtension();
    $time = time();
    //filename to store
    $filenametostore = $filename . '_' . $time . '.' . $extension;

    //The problem is here
    $request->file('profile_pdf')->storeAs('profile_pdfs', $filenametostore);
    

    return $filenametostore;
}

in storage, there is: storage/app/public/profile_pdfs/

My Form :

<form action="{{url('poste')}}" method="post" enctype="multipart/form-data">
@csrf

    <div class="mt-2">
        <label class=" block text-sm text-gray-600" for="cus_email">Upload</label>
        <input class="px-2 py-2 text-gray-700 rounded" type="file" name="profile_pdf" id="exampleInputFile">
    </div>


    <div class="mt-4">
      <button class="px-4 py-1 text-white font-light tracking-wider bg-gray-900 rounded" type="submit">Publier</button>
    </div>


</form>

My controller :

if($files = $request->hasFile('profile_pdf'))
    {

        $filenametostore = $this->getFilenametostore($request);


        $p = new Poste;
        $p->pdf = $filenametostore;
        $p->save();

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


Solution 1:[1]

Go to php.ini file uncomment "upload_tmp_dir" and set the value c:\windows\temp

;upload_tmp_dir =

Replace like this upload_tmp_dir = c:\windows\temp if you use windows

Solution 2:[2]

You can try one of these method

$fileName = $file.'.'.$ext;
$request->file->storeAs($path, $fileName);
// or 
Storage::disk('local')->put($path . '/' . $fileName , $request->file);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shumon Pal
Solution 2 MamaWin