小编Ryr*_*yry的帖子

“路径不能为空”laravel

我想将 pdf 文件保存在存储文件夹中,但是当我在表单中插入文件并单击按钮时,它会显示错误“路径不能为空”。然而,路径并不空。这是我可以执行此操作的函数:

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;
}
Run Code Online (Sandbox Code Playgroud)

在存储中,有:storage/app/public/profile_pdfs/

我的表格:

<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 …
Run Code Online (Sandbox Code Playgroud)

laravel

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

laravel ×1