无法在codeigniter中上传带有文件上传类的pdf和doc类型文件

时间:2014-05-30 09:10:29

标签: jquery codeigniter file-upload

我想以pdf或doc类型的格式上传文件。但我得到的错误是“文件类型是不允许的”。但是当我用jpg,xml和png替换pdf和doc时,它运行正常。 控制器,

function app_doc_upload()
{
    $today = date("Y/m/d");
    if(strncmp($this->input->post('action'),'appdocupload',12) == 0){
    $file_type="APP_DOCUMENT";
    $app_Code=$this->input->post('app_Code');
    $doc_Code=$this->input->post('doc_Code');
    $doc_filename_ap = str_replace("/", "_", $app_Code);
    $doc_filename=$doc_Code."_FILE_".$doc_filename_ap;  //1_DOC_1_ML_1314_EKM
    $office=$this->session->userdata['ksdc_logged_in']['office_code'];
    $financial_year = $this->lams_master_model->get_financial_year();
    $folderName=$file_type.'_'.$financial_year;
    $doc_path='office_files/'.$office.'/'.$folderName;
    if(!is_dir($doc_path)){
         mkdir($doc_path,0777);
    }
    $file_name ='SelectedFile';
    $config['upload_path'] = $doc_path;
    $config['allowed_types'] = '*';     //  'gif|jpg|png|pdf';  
    $config['encrypt_name'] = FALSE;
    $config['file_name'] = $doc_filename;
    $config['remove_spaces'] = TRUE;
    $config['overwrite'] = FALSE;
    $this->load->library('upload', $config);
    if(!$this->upload->do_upload($file_name))
    {
        $er = $this->upload->display_errors();
        $this->outputJSON($er);
    }else{
        $update=$this->upload->data();
        $file_id = $this->tapal_model->get_file_no($app_Code);
        $data_fileDocument = array(
                'file_id' => $file_id,
                'filedoc_path' => $doc_path.'/'.$update['file_name'],
                'filedoc_name' => $doc_Code,
                'file_attachdate' => $today,
                'attached_seat' => $this->session->userdata['ksdc_logged_in']['seat_id'],
                'file_attachtype' => 'DA'
                );
        if($this->offlineRegistration_model->insert_fileStatementDetails($data_fileDocument)){
            $this->outputJSON($doc_path.'/'.$update['file_name'], 'success');
        }else
            $this->outputJSON('Insertion failed', 'success');
        }
    }
}

剧本

$("#upload_doc_btn").click(function(){
var app_code = $.trim($("#appno").html());
var sel_doc = $.trim($("#sel_app_document").val()); 
var doc_file = document.getElementById('doc_file');
if(app_code==''){
  $("#msg_doc_upload").html('Busy! Refresh and try again');
  return false;
}else if(sel_doc==''){
  $("#msg_doc_upload").html('Please specify Document name');
  return false;
}else if(doc_file.files.length === 0){
  $("#msg_doc_upload").html('Please upload '+$('#sel_app_document').val()+' Document');
  return false;
}else{
  $("#msg_doc_upload").html('');
  var data = new FormData();
  data.append('SelectedFile', doc_file.files[0]);
  data.append('action','appdocupload');
  data.append('doc_Code',sel_doc);
  data.append('app_Code',app_code);
  var request = new XMLHttpRequest();
  request.onreadystatechange = function(){
  if(request.readyState == 4){
  try {
  var resp = JSON.parse(request.response);
  } catch (e){
  var resp = {
  status: 'error',
  data: 'Unknown error occurred: [' + request.responseText + ']'
  };
  }
  if(resp.status=="success"){ 
  $("#msg_doc_upload").html('');    //  document.getElementById("tbl_doc_upload").reset();  //
  $("#sel_app_document").val('');
  $("#doc_file").val('');
  $("#tbl_doc_upload").fadeOut(400);
  }else{
  $("#msg_doc_upload").html(resp.data);
  }
  }
  };
  request.open('POST', '<?php echo site_url('employee/app_doc_upload'); ?>');
  request.send(data);
}
});

0 个答案:

没有答案