首页 后端开发 php教程 !Codeigniter无法调用PHPExcel

!Codeigniter无法调用PHPExcel

Jun 13, 2016 am 11:19 AM
csv gt nbsp this

紧急求助!Codeigniter无法调用PHPExcel
我是初学Codeigniter,使用其文件上传类将csv或者excel文件上传,同时,使用过PHPExcel来读取内容,装入数据库。我的程序如下:
controllers/products.php文件:

        $memsn = $this->session->userdata('MEMSN');
$this->load->library('Excel_Read_Operat');
$groups = array('purchaser', 'salesman', 'viewer','merchant');
        if ($this->ion_auth->in_group($groups))
{
$this->session->set_flashdata('message', $this->lang->line("access_denied"));
$data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
redirect('module=products', 'refresh');
}

$this->form_validation->set_rules('userfile', $this->lang->line("upload_file"), 'xss_clean');

if ($this->form_validation->run() == true)
{
    if ( isset($_FILES["userfile"])){
                $this->load->library('upload_photo');

$dest_dir = 'uploads/'.$memsn.'/';

$this->dest_dir_fortest = $dest_dir;

if($this->upload_photo->direct_is_exists($dest_dir)){

}else{
    redirect("module=products&view=upload_csv", 'refresh');
}

$config['upload_path'] = $dest_dir;
$config['allowed_types'] = 'csv|xls|xlsx';
$config['max_size'] = '2048';
$config['overwrite'] = TRUE;

$old_file_name = $_FILES["userfile"]["name"];
$new_file_name = $this->getSystemTime().$_FILES["userfile"]["name"];
$config['file_name'] = $new_file_name;

//Initialize
$this->upload_photo->initialize($config);

if( ! $this->upload_photo->do_upload()){

//echo the errors
$error = $this->upload_photo->display_errors();
$this->session->set_flashdata('message', $error.$dest_dir);
redirect("module=products&view=upload_csv", 'refresh');
}


if ($this->upload_photo->file_ext == '.csv') {

$csv = $this->upload_photo->file_name;


Excel_Read_Operat::initialized($dest_dir.$new_file_name);


$phpexcel_csv_arr_table = Excel_Read_Operat::GetArrTable_CVS();



if(!empty($phpexcel_csv_arr_table)){
                    $keys = array('code','name','category_id','STATUS','DESCRIPTION','DECDESCTION','CUSTPRICE','LENGTH','HEIGHT','WIDTH','STATUS');
    $final = array();

foreach ($phpexcel_csv_arr_table as $row_csv_value){

$final[] = array_combine($keys, $value);

foreach($final as $csv_pr) {
if($this->products_model->getProductByCode($csv_pr['code'])) {
     $this->session->set_flashdata('message', $this->lang->line("check_product_code")." (".$csv_pr['code']."). ".$this->lang->line("code_already_exist"));
redirect("module=products&view=upload_csv", 'refresh');
}

}

}

在libraries/下,有Excel_Read_Operat.php类文件,和Excel文件夹,文件夹下是PHPExcel.php和PHPExcel文件夹。Excel_Read_Operat.php类如下:

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

解决方法:您的组织要求您更改 PIN 码 解决方法:您的组织要求您更改 PIN 码 Oct 04, 2023 pm 05:45 PM

解决方法:您的组织要求您更改 PIN 码

Windows 11 上调整窗口边框设置的方法:更改颜色和大小 Windows 11 上调整窗口边框设置的方法:更改颜色和大小 Sep 22, 2023 am 11:37 AM

Windows 11 上调整窗口边框设置的方法:更改颜色和大小

如何在 Windows 11 上更改标题栏颜色? 如何在 Windows 11 上更改标题栏颜色? Sep 14, 2023 pm 03:33 PM

如何在 Windows 11 上更改标题栏颜色?

OOBELANGUAGE错误Windows 11 / 10修复中出现问题的问题 OOBELANGUAGE错误Windows 11 / 10修复中出现问题的问题 Jul 16, 2023 pm 03:29 PM

OOBELANGUAGE错误Windows 11 / 10修复中出现问题的问题

Windows 11 上启用或禁用任务栏缩略图预览的方法 Windows 11 上启用或禁用任务栏缩略图预览的方法 Sep 15, 2023 pm 03:57 PM

Windows 11 上启用或禁用任务栏缩略图预览的方法

华为GT3 Pro和GT4的差异是什么? 华为GT3 Pro和GT4的差异是什么? Dec 29, 2023 pm 02:27 PM

华为GT3 Pro和GT4的差异是什么?

Windows 11 上的显示缩放比例调整指南 Windows 11 上的显示缩放比例调整指南 Sep 19, 2023 pm 06:45 PM

Windows 11 上的显示缩放比例调整指南

10种在 Windows 11 上调整亮度的方法 10种在 Windows 11 上调整亮度的方法 Dec 18, 2023 pm 02:21 PM

10种在 Windows 11 上调整亮度的方法

See all articles