i will get exception that is
{"error":{"type":"ErrorException","message":"Undefined index: image_Name","file":"E:\\xampp new\\htdocs\\system\\app\\controllers\\AccountController.php","line":293}}
this is my html form
<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>
this is my ajax code
$(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>');
}
}
});
});
this is my controller
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;
}
It is because the form attribute enc-type is missing
Pass:
<form method="post" enctype="multipart/form-data"></form>
enc-type is mandatory for file upload
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.