Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I upload .docx using Codeigniter? (PHP)

I'm attempting to upload a .docx using the upload helper in Codeigniter.

public function upload($id,$type){
        $folder = $type;
        $config['upload_path'] = RESOURCE_PATH . $folder;
        $config['allowed_types'] = 'pdf|doc|docx';
        $config['max_size'] = '100000';
        $this->CI->load->library('upload',$config);
        //$this->load->library('upload', $config);
        if (!$this->CI->upload->do_upload('userfile')){
            echo $this->CI->upload->display_errors();
        }
 ....

The upload function works fine on my local host. However, when I try uploading the .docx file on the server I get "The filetype you are attempting to upload is not allowed".

I can upload other files on the server and the code is an exact copy of what I have locally. I also googled around and found some people changed the mime for .docx to:

'docx'  =>  array('application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/octet-stream')  

but that doesn't seem to have resolved the issue. What could be going wrong and how do I resolve the issue so I can resolve this issue?

like image 740
Sheldon Avatar asked Aug 14 '13 14:08

Sheldon


People also ask

How do you upload a Word document into CodeIgniter?

docx using the upload helper in Codeigniter. public function upload($id,$type){ $folder = $type; $config['upload_path'] = RESOURCE_PATH . $folder; $config['allowed_types'] = 'pdf|doc|docx'; $config['max_size'] = '100000'; $this->CI->load->library('upload',$config); //$this->load->library('upload', $config); if (!

How can upload file path in CodeIgniter?

It depends upon how you are storing the uploaded data. If you are simply storing like: $data = $this->upload->data(); then access it by $data['full_path']; else if you are storing like $data = array('upload_data' => $this->upload->data()); then access it by $data['upload_data']['full_path'].

Which method is used to upload file in CodeIgniter?

File uploading in CodeIgniter has two primary parts—the frontend and the backend. The frontend is taken care of by the HTML form that uses the form input type file. On the backend, the file upload library forms the submitted input from the form and writes it to the transfer registry.

How can I read a docx file in PHP?

You can use your existing database or copy and paste this into MySQL. INSERT INTO `infodoc` (`fileid`, `filename`, `directory`, `created_date`) VALUES (1, 'etp. docx', '/document/', '2020-06-22'); Next, we have created a PHP file 'index.


1 Answers

Try to add this mime type: application/zip to application/config/mimes.php for docx. It works for me. If it not help. Open system/libraries/Upload.php(line 205) and do this:

var_dump($this->file_type);
exit();

You will see file type of you .docx and need to add it to docx mimes list in config.

like image 166
joni jones Avatar answered Oct 11 '22 17:10

joni jones