file type crt as mime - mtso86 - 06-15-2019
I do face an issue when using upload library
since when trying to upload a CRT file (Certificate File) which has a mime type of Content-Type: application/pkix-cert
it gives me file type not allowed
I checked the mimes.php and it has a record for crt as follow:
'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert')
so any suggestions please
note: when I use $config['allowed_types'] = '*';
it works without errors
RE: file type crt as mime - jreklund - 06-15-2019
I have seen similar problems using Dropzone, where the file are uploaded using javascript instead of a normal form. It will change the context-type, you can see it in your networks tab what you are submitting.
Are you using AJAX as well? You will need to supply a little more code to get a better answer.
Side not: I didn't resolve my image upload problem, I validate it after upload instead.
RE: file type crt as mime - mtso86 - 06-15-2019
(06-15-2019, 11:07 AM)jreklund Wrote: I have seen similar problems using Dropzone, where the file are uploaded using javascript instead of a normal form. It will change the context-type, you can see it in your networks tab what you are submitting.
Are you using AJAX as well? You will need to supply a little more code to get a better answer.
Side not: I didn't resolve my image upload problem, I validate it after upload instead.
thanks for your kind reply
sure I do use AJAX
I do check the post of ajax and it states a correct type
here is ajax code
Code: function do_upload(){
$(".error-message").empty();
$('#upl_btnUpload').linkbutton({text:'Saving...'});
$('#upl_btnUpload').linkbutton('disable');
var formData = new FormData($('#form_upload')[0]);
$.ajax({
url:"<?php echo base_url('webconfig/auth/get_new_csrf');?>",
type:"GET",
dataType:"JSON",
success:function(data){
formData.append(data.csrf_name,data.csrf_token);
$.ajax({
url : "<?php echo base_url('webconfig/network/ajax_upload_crt')?>",
type: "POST",
data: formData,
contentType: false,
processData: false,
dataType: "JSON",
success:function(data){
if(data.error_status){
toastr.success(data.error_string);
$('#w_upl_crt').window('close');
}else{
if(data.error_type=='validate'){
toastr.error(data.error_string);
for (var i = 0; i < data.error_input.length; i++){
err('[id="'+data.error_input[i]+'"]', data.error_string[i]);
}
}else{
$.messager.alert('PediaERP',data.error_string,'error');
}
}
$('#upl_btnUpload').linkbutton({text:'Save'});
$('#upl_btnUpload').linkbutton('enable');
},
error: function (jqXHR, textStatus, errorThrown){
$.messager.alert('PediaERP','Error uploading certificate !','error');
}
});
},
error: function (jqXHR, textStatus, errorThrown){
$.messager.alert('PediaERP','Error saving certificate !','error');
$('#upl_btnUpload').linkbutton({text:'Save'});
$('#upl_btnUpload').linkbutton('enable');
}
});
}
and here is the php code which handles the request
PHP Code: public function ajax_upload_crt(){ //$validate_status = $this->_validate('net_upload_crt'); //if($validate_status['error_status']==FALSE){ // echo json_encode($validate_status); // exit; //} $ssl_id_old = $this->input->post('upl_ssl_id'); $ssl_details = $this->m_ssl->get_ssl_details($ssl_id_old);
if(!empty($_FILES['upl_crt_file']['name'])){ //echo mime_content_type($_FILES['upl_crt_file']['name']); $config['upload_path'] = './uploads'; $config['allowed_types'] = 'crt'; $config['max_size'] = 1024; $config['overwrite'] = TRUE; $config['file_name'] = $ssl_details->ssl_domain.".crt"; $this->load->library('upload', $config); $this->upload->initialize($config); if(!$this->upload->do_upload('upl_crt_file')){ //upload failed $err_status = array( 'error_status' => FALSE, 'error_type' => 'system', 'error_string' => $this->upload->display_errors(), 'error_input' => NULL, 'ssl_id' => NULL ); echo json_encode($err_status); }else{ //upload success rename("/pediaerp/uploads/".$ssl_details->ssl_domain.".crt", "/etc/ssl/pediaerp/crt/".$ssl_details->ssl_domain.".crt"); //get ssl_id $ssl_id = $this->m_ssl->get_new_ssl_id()->ssl_id; //read crt file $cert_data = openssl_x509_parse(file_get_contents("/etc/ssl/pediaerp/crt/".$ssl_details->ssl_domain.".crt")); $valid_from = date('Y-m-d',$cert_data['validFrom_time_t']); $valid_to = date('Y-m-d',$cert_data['validTo_time_t']); $days = date_diff(new DateTime($valid_to), new DateTime($valid_from))->format('%a'); //$omari_cert = print_r($cert_data); //prepare sslData $sslData = array( "ssl_type_id" => 3, "ssl_id" => $ssl_id, "ssl_domain" => $ssl_details->ssl_domain, "ssl_common" => $cert_data['subject']['CN'], "ssl_country" => $cert_data['issuer']['C'], "ssl_state" => $cert_data['issuer']['ST'], "ssl_organization" => $cert_data['issuer']['O'], "ssl_ou" => $cert_data['subject']['OU'][0], "ssl_locality" => $cert_data['issuer']['L'], "ssl_email" => $ssl_details->ssl_email, "ssl_days" => $days, "valid_from" => $valid_from, "valid_to" => $valid_to, "is_uploaded" => 1 ); $db_insert = $this->m_ssl->upload_crt($sslData,$ssl_id_old); echo json_encode($db_insert); } } }
|