无法在codeigniter中上传excel文件 [英] unable to upload an excel file in codeigniter

查看:162
本文介绍了无法在codeigniter中上传excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Codeigniter项目,可以通过上传Excel文件并使用PHPExcel读取数据,将数据插入到数据库中。它在我的本地主机上工作,但是当我将它上载到LAMP服务器时,它给了我一个错误你正试图上传的文件类型是不允许的。我该如何解决这个问题?

>

编辑
在我的项目中,我也有一个文件图像上传。

  public function uploadConfig(){
$ this-> load-> library('PHPExcel');
$ this-> load->库('PHPExcel / IOFactory');
$ config ['upload_path'] ='./csv_uploads/';
$ config ['allowed_types'] ='xlsx | csv | xls';
$ config ['max_size'] ='10000';
$ config ['overwrite'] = true;
$ config ['encrypt_name'] = FALSE;
$ config ['remove_spaces'] = TRUE;

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

if(!is_dir('csv_uploads'))
{
mkdir('./ csv_uploads',0777,true);

// gif | jpg | jpeg | png
}

这在 XAMPP 的本地主机上运行。但是,当我将它上载到我的 LAMP 服务器上时,它不起作用。 您尝试上传的文件类型是不允许的由于您的文件类型错误或未完成,因此发生此问题。



请在下面申请步骤来获得你的文件类型。

你可以看看系统/库/ Upload.php行199:

  $这 - > _file_mime_type($ _ FILES [$场]); 

将该行更新为:

  $ this-> _file_mime_type($ _ FILES [$ field]);的var_dump($这 - > FILE_TYPE);死(); 

现在您可以看到您的实际文件类型如xlsx或csv或xls或ods



现在你可以在代码中添加你的文件类型
$ b $ $ $ $ $ $ $ $ config $'allowed_types' ='xlsx | csv | xls';

也加入 config / mimes.php

I have a Codeigniter project that can insert data into database through uploading an excel file and reading it with PHPExcel. It is working on my localhost however when I uploaded it in a LAMP server, It gives me an error The filetype you are attempting to upload is not allowed. How am I going to solve this?

EDIT In my project, I also have a file image uploading..

 public function uploadConfig(){
    $this->load->library('PHPExcel');  
    $this->load->library('PHPExcel/IOFactory');
    $config['upload_path'] = './csv_uploads/'; 
    $config['allowed_types'] = 'xlsx|csv|xls';
    $config['max_size'] = '10000'; 
    $config['overwrite'] = true;
    $config['encrypt_name'] = FALSE;
    $config['remove_spaces'] = TRUE;

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

    if (!is_dir('csv_uploads'))
    {
        mkdir('./csv_uploads', 0777, true);
    }
    // gif|jpg|jpeg|png
}

This works on my localhost in XAMPP. However, when I uploaded it on my LAMP server, it didn't work.

解决方案

For The file type you are attempting to upload is not allowed this issue occur because of your file type is wrong or not fulfill.

Please apply below step to get your file type.

You can looking at system/libraries/Upload.php line 199:

$this->_file_mime_type($_FILES[$field]);

Update that line to:

 $this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();

Now you can see your actual file type Like xlsx or csv or xls or ods

Now you can add your file type below code

$config['allowed_types'] = 'xlsx|csv|xls';

also add in config/mimes.php

这篇关于无法在codeigniter中上传excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆