2016-10-14 67 views
0

我會得到的例外是:「ErrorException」,「message」:「Undefined index:image_Name」,「file」:「E:\ xampp new \ htdocs \ system \ app \ controllers \ AccountController.php」,「line」 :293}}

{ 「錯誤」:{ 「類型」: 「ErrorException」, 「消息」: 「未定義指數: IMAGE_NAME」, 「文件」:「E :\ XAMPP 新的\ htdocs中\系統\程序\ \控制器AccountController.php」, 「線」:293}}

這是我的HTML表單

<form role="form" method="PATCH" action="{{URL::route('staff-new')}}" id="post-form"> 
        <div class="box-body floating_block"> 
        <div class="form-group"> 
         <label for="exampleInputEmail1">User Name</label> 
         <input type="text" name="username" class="form-control" id="exampleInputEmail1" > 
        </div> 
        <div class="form-group"> 
         <label for="exampleInputEmail1">User Display Name</label> 
         <input type="text" name="display_Name" class="form-control" id="exampleInputEmail1" > 
        </div> 
        <div class="form-group"> 
         <label for="exampleInputEmail1">Password</label> 
         <input type="password" name="password" class="form-control" id="exampleInputEmail1" > 
        </div> 
        <div class="form-group"> 
         <label for="exampleInputEmail1">Confirm Password</label> 
         <input type="password" name="password_confirmation" class="form-control" id="exampleInputEmail1" > 
        </div> 
        <div class="form-group"> 
         <label for="exampleInputEmail1">Email</label> 
         <input type="text" name="email" class="form-control" id="exampleInputEmail1" > 
        </div> 
        <div class="form-group"> 
         <label for="exampleInputEmail1">Phone</label> 
         <input type="text" name="phone" class="form-control" id="exampleInputEmail1" > 
        </div> 

        <div class="form-group"> 
         <label for="exampleInputEmail1">User Designation</label> 
         <select type="text" name="user_Role" class="form-control" id="exampleInputEmail1" placeholder="Enter Category Name"> 

         @foreach($designation as $key=>$data) 
         <option value="{{$key}}">{{$data}}</option> 
         @endforeach 
         </select> 
        </div> 
        <div class="form-group" > 
         <label for="exampleInputPassword1">Profile Image</label> 
         <input type="file" name="image_Name" class="form-control" id="" accept="image/*"> 
        </div> 
        <div class="form-group "> 
        <button type="submit" class="btn btn-primary submit-form-ajax-validation submit_btn">Submit</button> 

這是我的Ajax代碼

$(document).on('click', '.submit-form-ajax-validation', function(e) 
{ 
    e.preventDefault(); 
    var fonturl = $('#post-form').attr('action'); 
    var method=$('#post-form').attr('method'); 
    //alert(fonturl); 
    $.ajax({ 
    url : fonturl, 
    type: method, 
    data: $('#post-form').serialize(), 
    async: false, 
    success: function(data) 
    { 
     if(data.msg=="Yes") 
     { 
      $(document).trigger('showMessage','<a href="javascript:void(0)" id="cross_icon_rq" ><i class="fa fa-times-circle-o cross_icon_cs" class=""></i></a><div class="text_success_cs"><strong>Success!</strong><br />'+data.text+'</div>'); 
      $('#post-form').reset; 
     }else if(data.msg=="No") 
     { 
      $(document).trigger('showMessage','<a href="javascript:void(0)" id="cross_icon_rq"><i class="fa fa-times-circle-o cross_icon_cs" class=""></i></a><div class="text_error_cs"><strong>Error!</strong><br /> '+data.text+'</div>'); 


     }else if(data.msg=="validation_error") 
     { 
      var msg=''; 
        $.each(data.error, function(index,element)         
         { 

           //console.log(element); 
           if(index.length>0) 
            { 
             $('#'+index).addClass('validation_error_cs'); 
             //console.log(response[error][index2]); 
             msg=msg+element+'<br />'; 
            } 


         }); 
         $('.responseMessage_rq').removeClass('error_block_cs'); 
         $('.responseMessage_rq').removeClass('success_block_cs'); 
         $('.responseMessage_rq').addClass('error_block_cs'); 
         $(document).trigger('showMessage','<a href="javascript:void(0)" id="cross_icon_rq" ><i class="subhocross1 cross_icon_cs" ></i></a><div class="text_error_cs"><div class="text_heading_cs"><strong>Error!</strong></div>'+ msg+'</div>');  
     } 

    } 
    }); 
}); 

這是我的控制器

   if($input['image_Name']!='') 
       { 
        $filename = $_FILES['image_Name']; 
        if (!empty($filename)) 
        { 
         $filename = Input::file('image_Name')->getClientOriginalName(); 
         $splitName = explode(".", $filename); 

         $fileExt = end($splitName); 
         $newFileName = strtolower('profile_image_'.time().'.'.$fileExt); 
         // 
         $destinationPath = base_path(). '/public/uploads/profile_image/'; 
         //dd($destinationPath); 
         if(!file_exists($destinationPath)) 
         { 
          mkdir($destinationPath,0777,true); 
         } 
         $rules = array('myfile' => 'mimes:jpg,jpeg,png'); 
         $size = Input::file('image_Name')->getSize(); 

         $data = array('myfile' => Input::file('image_Name')); 

         $validation = Validator::make($data,$rules); 
         //dd($size); 
         if ($validation->fails()) 
         { 
          $response['Success']="format_na"; 
           return $response; 
         } 

回答

1

這是因爲表單屬性ENC-type丟失

通行證:

<form method="post" enctype="multipart/form-data"></form> 

enc-type文件上傳是必需的

+0

look $ filename = Input :: file('image_Name') - > getClientOriginalName(); ,它可以命名爲小寫,如「image_name」 –

相關問題