am uploading files using ajax in Codeigniter
the problem is when i upload some videos sometimes it upload it sometimes it doesn't (ajax error:function runs ) although ,i put max_size config to 1000000 and i tried to set max_size to 0 (no limit) but it still showing error when i upload big files or videos . here is my controller
public function add_product()
{
if($this->input->post("product_title")){
$title = $this->input->post('product_title');
$description = $this->input->post('product_description');
$price = $this->input->post('product_price');
$quantity = $this->input->post('product_quantity');
$config['upload_path']= './images/';
$config['allowed_types'] = 'jpg|jpeg|png|gif|mp3|mp4';
$config['max_size'] = '1000000';
$this->load->library('upload',$config);
if(!$this->upload->do_upload('image')){
$error = array('error' => $this->upload->display_errors());
echo json_encode($error);
die();
return false;
}else{
$image =$this->upload->data();//= $image =$_FILES["image"]["name"];
$data = array('title'=>$title,'description'=>$description,'price'=>$price,'quantity'=>$quantity,'image'=>$image['file_name']);
if($this->Products_model->create_product($data)){
echo json_encode($image);
//////////original
//echo $image['file_type'];
}else{
return false;
}
}
//end if
}
///end method
}
and this is my ajax
$.ajax({
type:'post',
url: baseURL+"/admin/Products/add_product",
data:postData2,
dataType: 'json',
contentType: false,
cache: false,
processData:false,
success:function(data){
// $('#uploaded_image').html(data['file_type']);
if(data.error){
alert(data.error);
return false;
}
$('#register_form_products')[0].reset();
AddNotification('add_product');
SetNotificationModal('new product is added');
} ,
error: function() {
alert('error');
}
});
update
error: function(jqXHR, textStatus, errorThrown) {
alert('error look at console for more info ');
console.log('jqXHR:');
console.log(jqXHR);
console.log('textStatus:');
console.log(textStatus);
console.log('errorThrown:');
console.log(errorThrown);
}
i copied this code from google to show the error in console so this is the error
parsererror
468:1062 errorThrown:
468:1063 SyntaxError: Unexpected end of JSON input
at parse (<anonymous>)
at Ut (jquery.min.js:2)
at k (jquery.min.js:2)
at XMLHttpRequest.<anonymous> (jquery.min.js:2)
468:1058 jqXHR:
468:1059 Object
468:1060 textStatus:
468:1061 parsererror
468:1062 errorThrown:
468:1063 SyntaxError: Unexpected end of JSON input
at parse (<anonymous>)
at Ut (jquery.min.js:2)
at k (jquery.min.js:2)
at XMLHttpRequest.<anonymous> (jquery.min.js:2)