I am working on a project in codeigniter 3 , the problem I have is when downloading the file, when uploading the file to the server, I keep the path and the database in the database. name generated by the function do_upload
of codeigniter , when I download it download it well but without content, either for word excel documents like pdf, when trying to open these files it shows them empty and in the pdf case does not open it, when viewing the documents on the server they are all complete with their content.
At the time of sending the file, I sent it via ajax using FormData
and send it correctly.
Here's the upload code:
public function document(){
$config['allowed_types'] = 'docx|xlsx|pdf';
$config['upload_path'] = './assets/archivos/doc/';
$config['remove_spaces'] = TRUE;
$config['max_size'] = '20048';
$this->load->library('upload', $config);
if(!$this->upload->do_upload('file')){
$error = $this->upload->display_errors();
$result = array('error' => true, 'mens' => $error, 'estado' => 3);
echo json_encode($result);
}else{
$data = array(
'nom_doc' => $this->upload->data('file_name'),
'doc_size' => $this->upload->data('file_size'),
'type_doc' => $this->upload->data('file_type'),
'ruta_doc' => $this->upload->data('full_path'),
'id_conf_sist' => 1
);
$res = $this->Config_model->insertDocument($data);
if($res){
$result = array('error' => false, 'mens' => 'El archivo '.$this->upload->data('raw_name').', a sido guardado correctamente.', 'estado' => 1);
echo json_encode($result);
}
}
}
This would be the code to download:
public function getDownloadFile($name){
$data = file_get_contents($this->folder.$name);
force_download($name,$data);
}
Someone could tell me what would be the error for which I do not download the files well.