如何使用Codeigniter上传.docx? (PHP) [英] How do I upload .docx using Codeigniter? (PHP)
问题描述
我正在尝试使用Codeigniter中的上传帮助器上传.docx。
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();
}
....
上传功能在我的本地计算机上工作正常主办。但是,当我尝试在服务器上上载.docx文件时,出现不允许您尝试上载的文件类型。
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".
我可以在其他上载其他文件服务器和代码是我在本地拥有的确切副本。我还四处搜寻,发现有人将.docx的mime更改为:
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?
推荐答案
尝试添加以下MIME类型: application / zip
到 application / config / mimes.php
for docx
。这个对我有用。
如果没有帮助。打开 system / libraries / Upload.php
(第205行),然后执行以下操作:
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();
您将看到.docx的文件类型,需要将其添加到配置中的docx哑剧列表中。
You will see file type of you .docx and need to add it to docx mimes list in config.
这篇关于如何使用Codeigniter上传.docx? (PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!