An 'invalid file type' error occours when i try to upload a docx file to server using codeignitor upload function but it works fine in local server and also in case of pdf,doc and image files .
Below is my file upload script .
I use ajaxuploader to upload file
<script>
//.......................FILE UPLOAD ...........................................
$(function(){
var btnUpload=$('#nefile');
new AjaxUpload(btnUpload, {
action: '<?php echo site_url('userdashboard/saveabstractdocument'); ?>',
name: 'file',
onComplete: function(file, response){
if(response)
{
if(response == 1){
$('#abstractdoc').css('display','none');
$('#abstractval').css('display','block');
}else{
//$('#metaimgval_error').html("");
$("#val").val(response);
$('#abstractval').css('display','none');
}
} else
{
}
}
});
});
//.......................FILE UPLOAD ENDS...........................................
</script>
below is my controller function
function saveabstractdocument() {
$abstractfile = $_FILES["file"]["name"];
$filenme = $_FILES["file"]["name"];
$ext = explode(".", $filenme);
$cnt = count($ext) - 1;
$filenme = date("m") . date("d") . date("Y") . time() . "." . $ext[$cnt];
$fil = date("m") . date("d") . date("Y") . time();
$config['upload_path'] = './uploads/abstract/';
$config['file_name'] = $fil;
$config['allowed_types'] ='pdf|doc|docx';
$config['max_size'] = '';
$this->load->library('upload', $config);
if (!$this->upload->do_upload("file")) {
$data["err"] = array('error' => $this->upload->display_errors());
// print_r($this->upload->display_errors());exit;
echo 1;
} else {
$this->load->library('session');
$datafile = array
(
'fname' => $filenme
);
$this->session->set_userdata($datafile);
echo $abstractfile;
}
}
Why don'y you use like this in view...
<input type="file" name="file"/>
or in your question invalid type maybe its not included in your mimes.php the doc,pdf,docx and your $config['max_size'] = ''; if you will not put any value you can remove that.
also here my sample of upload file
$config['upload_path'] = './files/contracts-csv/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '4096';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
$this->upload->display_errors('', '');
if (!$this->upload->do_upload("csv_file")) {
echo $this->upload->display_errors(); die();
$this->data['error'] = array('error' => $this->upload->display_errors());
} else {
$upload_result = $this->upload->data();
$pathfile = $upload_result['full_path'];
}
...Hopes i give you idea