2016-03-23 125 views
2

我在笨framework.I工作要上传文档或DOCX file.So我有这样写代码:无法上传DOC或DOCX文件笨

$config['upload_path'] = './uploads/resume/'; 
$config['allowed_types'] = 'docx|doc|DOC|DOCX'; 

$this->upload->initialize($config); 

if (! $this->upload->do_upload('resume')) 
{ 
    print_r($error = array('error' => $this->upload->display_errors())); 
} 
else 
{ 
    $upload = $this->upload->data(); 
    print_r($upload);exit; 
} 

在这里,它显示和错误,如您正试图上传的文件类型不被允许。和文件没有上传。

我也修改mimes.php文件,并添加

'doc' => array('application/msword', 'application/vnd.ms-office'), 
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'), 

当我打印$这个 - > upload->数据()话,就说明FILE_TYPE为应用/ vnd.oasis。 opendocument.text

但是,它不工作。所以我怎样才能上传文档或docx文件?

+0

什么是您的CI版本? –

+0

@Abdulla它的2.2.6 –

+0

你加载库? –

回答

0

我在允许的MIME类型数组中看不到“application/vnd.oasis.opendocument.text”。

+0

我需要在doc数组中写** application/vnd.oasis.opendocument.text **吗? –

+1

是的,你应该。如果您正在上传的文件是.doc,请将其添加到“doc”数组中。如果它是.docx,则将其添加到该数组中。 您可能会发现更多的MIME类型,它取决于创建文件的应用程序。因此,当上传失败时总是记录该值,以便将来可以添加它们。 –

1

在这里,我已经创建的文档数组中mimes.php这样的:

'doc' => array('application/msword', 'application/vnd.ms-office','application/vnd.oasis.opendocument.text') 

和工作。

0

不要忘记max_size并允许类型txt

$config['allowed_types']  = 'txt|doc|docx'; 
$config['max_size']    = 10000; 

$this->load->library('upload', $config); 

如果仍然无法负载的OpenOffice延伸

$config['allowed_types'] = 'application/vnd.oasis.opendocument.spreadsheet | application/vnd.oasis.opendocument.text | application/vnd.oasis.opendocument.presentation | 
application/vnd.openxmlformats-officedocument.wordprocessingml.document | application/vnd.ms-excel | application/vnd.openxmlformats-officedocument.presentationml.presentation | txt'; 
0

将以下内容添加到mimes.php文件中

'binary/octet-stream' 

对于您想要支持的每种办公文档类型。不是一个理想的解决方案,但为我工作。