为了账号安全,请及时绑定邮箱和手机立即绑定

上传的图像为空 Laravel,我收到此错误 file_get_contents():

上传的图像为空 Laravel,我收到此错误 file_get_contents():

PHP
蝴蝶刀刀 2023-07-08 17:44:01
我试图将上传到表单的图像转换为 Laravel 中的 Base 64,但上传的图像为空刀片文件-->(查看)<body>       <form action="{{Route('PostImageProcess')}}" enctype='multipart/form-data'>        {{ csrf_field() }}        <div class="form-group">            {{-- {!! Form::label($for, $text, [$options]) !!} --}}            <label for="img">post Image</label>            <input type="file" name="image" id="img">        </div>        <input type="submit">    </form></body>内部控制器-->public function PostImageProcess(Request $request){    // $image = base64_encode(file_get_contents($request->file('image')));        $ima= base64_encode(file_get_contents($request->file('image')));    echo $ima;        $image="11221";           return view('afterPostSuccess')->with("body",$image);    }我收到此错误: file_get_contents(): 文件名不能为空
查看完整描述

1 回答

?
达令说

TA贡献1821条经验 获得超6个赞

您没有验证您的Request $request


        $valid = $request->validate([

                     'image' => 'required|max:100024',

                ]);


         $ima= base64_encode(file_get_contents($request->file('image')));

         echo $ima;


          $image="11221";

          return view('afterPostSuccess')->with("body",$image);

更新


编辑您的表单,如下所示:


  <body>

     <form method="post" action="{{Route('PostImageProcess')}}" enctype='multipart/form-data'>

       {{ csrf_field() }}

      <div class="form-group">

          {{-- {!! Form::label($for, $text, [$options]) !!} --}}

          <label for="img">post Image</label>

          <input type="file" name="image" id="img">

      </div>

      <input type="submit">

    </form>

  </body>


查看完整回答
反对 回复 2023-07-08
  • 1 回答
  • 0 关注
  • 77 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信