!Codeigniter無法調用PHPExcel

來源:互聯網
上載者:User
緊急求助!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');
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.