dongzhi4239 2015-11-08 02:25
浏览 8

文件未被发送到控制器

I am trying to open a form which will take in a picture (from the camera) and than send it to my controller in laravel.

Does any body know why this is not working?

Form in laravel:

    <div style="width: 0; height: 0; overflow: hidden;">
   {{ Form::open(array('route' => 'upload_photo', 'files' => true)) }}
      <input type="file" onchange="this.form.submit();" id="camera_input" name="camera_input" accept="image/*" capture="camera" />             
</div>
   <button class="btn btn-primary btn-lg normal-font" type="button" onclick="takePicture();">Take Picture And Upload</button>
   {{ Form::close(); }}

Javascript which will simply just open the camera/file select on click:

function takePicture() {
   document.getElementById("camera_input").click();
}

Laravel controller: All I am doing is this to try to see if the file gets put over here:

   public function upload_photo() {
      $file = Input::file('camera_input');
      var_dump($file);
   }

It is getting NULL printed out for $file though... Anyone know what I am doing wrong?

  • 写回答

1条回答 默认 最新

  • dongyao2022 2015-11-08 02:48
    关注

    I got it apparently my input type needed: enctype="multipart/form-data"

    I thought have files => true on the form for laravel would do this and thats what that was for but apparently it needed to be on the input type. Maybe because I didnt use laravel's Form::file()

    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上