亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

上傳的圖像為空 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 關注
  • 143 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號