!Codeigniter无法调用PHPExcel
Jun 13, 2016 am 11:19 AM
紧急求助!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');

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair

What are the differences between Huawei GT3 Pro and GT4?

10 Ways to Adjust Brightness on Windows 11
