javascript - Can't upload multiple image using Ajax with codeigniter -
wana upload multiple image of ajax in codeigniter got error while calling function upload_business_photo_do() please help
thanks in advance....
<input type="button" id="uploadbusinessimg" value="upload">
ajax code:- here call ajax via id="uploadbusinessimg"
<script> $("#uploadbusinessimg").on("click",function(e) { var total_img=$("#txtbusinessimage").get(0).files.length; if(total_img<=5) { var f_size=0; var f_size_1=0; var f_type_1="" ,validfilename="",invalidfilename=""; var chkfilevalid=true; for(var i=0; i<=total_img-1; i++) { var f_name=$("#txtbusinessimage").get(0).files.item(i).name; var f_size=$("#txtbusinessimage").get(0).files.item(i).size; var f_type=f_name.split('.').pop(); //alert(f_type); var valid_extensions = /(\.jpg|\.jpeg|\.png)$/i; if(valid_extensions.test(f_name)) { if(validfilename=="") validfilename =f_name; else validfilename+=","+f_name; } else { invalidfilename=f_name; chkfilevalid=false; break; } var newfilesize=parseint(f_size); f_size_1=parseint(f_size_1)+parseint(newfilesize); } var totalfilesize=f_size_1; //alert(totalfilesize); if(totalfilesize<=1572864 && chkfilevalid==true) { //alert("allow"); alert(validfilename); var businessimage=validfilename; $.ajax({ type:"post", url:"<?php echo site_url('main_ctrl/upload_business_photo_do'); ?>", mimetype:"multipart/form-data", uploadmultiple: true, data:{recivebusinessimg:businessimage}, success: function(reviceuploadimgmsg) { alert(reviceuploadimgmsg); } }); } else { if(chkfilevalid==false) alert("invalidfilename"+invalidfilename); else alert("image size should less 1.5 mb"); } } else { alert("not allow"); } }); </script>
this controller code:-
function upload_business_photo_do() { $recivebusinessimgname=$this->input->post('recivebusinessimg'); $newarray=explode(",",$recivebusinessimgname); /*code image*/ $config['upload_path']='./company_image/'; $config['allowed_types']= 'jpg|png|jpeg'; $config['max_width'] = '6000'; $config['max_height'] = '4500'; $this->load->library('upload',$config); for($i=0; $i<count($newarray); $i++) { $_files['userfile']['name']= $_files['txtbusinessimage']['name'][$i]; $_files['userfile']['type']= $_files['txtbusinessimage']['type'][$i]; $_files['userfile']['tmp_name']= $_files['txtbusinessimage']['tmp_name'][$i]; $_files['userfile']['error']= $_files['txtbusinessimage']['error'][$i]; $_files['userfile']['size']= $_files['txtbusinessimage']['size'][$i]; if(! $this->upload->do_upload()) { /*----set flash message*/ echo "error"; } else { $upload_data = $this->upload->data(); echo "done"; } } }
Comments
Post a Comment