0

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)
Mohamad Alasly
  • 330
  • 3
  • 17
  • I'd use ftp, not do_upload() ! allowed quotas for file upload depend on your hosting service, ftp is pretty much unlimited (only limited to the GB quote of your host) – Vickel Jul 18 '18 at 15:39

1 Answers1

1

Irregardless of what you set with $config['max_size'] = '1000000'; you most likely have a server limitation. This limitation is as defined by post_max_size and/or upload_max_size in the php.ini file (whichever is smaller takes precedence); for most providers this can't be changed even with ini_set().

There are a few options still to upload large files. Use a system that "chunks" the files or divides the file into smaller, manageable pieces, or use ftp. I believe dropzone supports chunking, however you would have to modify your script to handle this and most-likely wouldn't be able to use CI's uploader library.

Alex
  • 9,215
  • 8
  • 39
  • 82