如何在拉拉维尔提交文件


How to submit files in Laravel

我的表格如下

    {{ Form::open(array( 'enctype' => 'multipart/form-data'))}}
    <div class="vendor-box-wrap">
       <div class="page3-suggested-cat-wrap" style="float: left;width: 100%;border-bottom: 1px dotted;padding-bottom: 10px;margin-left: 20px;">
        <label style="width:9%;" for="9009" class="page3-suggested-cat-label" >BoQ</label>
        <div class="input-group" style="margin-top: 10px;
        width: 70%;">
        <span class="form-control"></span>
      <span class="input-group-btn">
        <span class="btn btn-primary" onclick="$(this).parent().find('input[type=file]').click();">Browse</span>
        <input  name="file|90009|107" id="file|9009" 
        value=""  onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[''|/]/).pop());" 
        style="display: none;" type="file">
      </span>
    </div>
    </br> <center><h2><strong>OR</strong></h2></center>
    </div>
    </div>
   <div class="next-btn-wrap"><div class="cf"></div>
    <div class="back-btn-wrap">
        {{ Form::submit('Back',array('class' => 'back-btn', 'name' => 'back'))}}
    </div>
    <div class="save-btn-wrap">
        {{ Form::submit('Save',array('class' => 'save-btn','name' => 'save'))}}
    </div>
    {{ Form::submit('Next',array('class' => 'next-btn','name' => 'next'))}}
</div>
{{ Form::close()}}

在我的控制器中,我使用以下代码来获取数据

$aa = Input::except(array('_token','back','save','next'));
            //dd($aa);
            foreach ($aa as $key=>$value){
                $ids = explode("|",$key);
                if(isset($ids[0]) && $ids[0]=="file" ){
                     $userid = Session::get('userid');
                     $event = Session::get('event');
                     $fileTblObj = new fileHandler();
                     $ans = Answer::find($ids[2]);
                    if(isset($aa[$key])){
                        //dd($aa[$key]);
                    if(Input::file($key)->isValid()) {
                          $destinationPath = 'app/uploads/'.$event.'/'.$userid.'/'.$pageNo ; // upload path
                          $extension = Input::file($key)->getClientOriginalExtension(); // getting image extension
                          $name = Input::file($key)->getClientOriginalName();
                          $curFilesize = Input::file($key)->getClientSize();
                          $mime =Input::file($key)->getMimeType();
                          if (!File::exists($destinationPath."/boq-".$name)){ 
                                //creating details for saving inthe file_handler Table
                                    $fileTblObj->user_id =  $userid;
                                    $fileTblObj->eventName = $event ; 
                                    $fileTblObj->fileName = "boq-".$name;
                                    $fileTblObj->formPage =$pageNo ;
                                    $fileTblObj->filePath = $destinationPath."/";
                                    $fileTblObj->mime= $mime;
                                    $ans->answer_text = 'Yes';

                                    Input::file($key)->move($destinationPath, "boq-".$name); // uploading file to given path
                                    //Input::file($key)->move($boqPath, $boqname); // uploading file to given path  
                                    //Save filedetails
                                    $fileTblObj->save();  
                                    $ans->save();
                                    Session::flash('success', 'Upload successfully'); 
                           }else if(File::size($destinationPath."/".$name) != $curFilesize){
                                    $fileDtls = $fileTblObj->where('uid',$userid)->where('fileName',$name)->where('formPage',$pageNo)->first();
                                    Input::file($key)->move($destinationPath, $name);
                                    $ans->answer_text = 'Yes';
                                    $ans->save(); 
                                    $fileTblObj->where('id',$fileDtls->id)->update(array('updated_at'=>date("Y-m-d h:m:s",time())));
                            }
                          //return Redirect::to('upload');
                        }
                    }
                    else
                    {
                        if($ans->answer_text =='')
                        {
                            $ans->answer_text = 'No';
                            $ans->save();
                        }
                    }
                }

我的问题是我无法在后端获取文件详细信息if 语句

if(isset($ids[0]) && $ids[0]=="file" ){
}

总是假的。

任何想法我如何解决这个问题。我还尝试将 FOrm 函数更改为

{{ Form::open(array('files' => true)) }}

仍然没有显示文件详细信息

要发送文件,我个人使用此方法。

视图:

{!! Form::open(array('action' => 'TestController@store', 'method' => 'POST', 'files'=>true)) !!}
  {!! Form::file('thefile') !!}
  {!! Form::submit('Save', array('class' => 'btn')) !!}
{!! Form::close() !!}

控制器:

$thefile = Input::file('thefile');

希望这有帮助!