!Codeigniter无法调用PHPExcel
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了!Codeigniter无法调用PHPExcel,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2530字,纯文字阅读大概需要4分钟。
内容图文
![!Codeigniter无法调用PHPExcel](/upload/InfoBanner/zyjiaocheng/221/1b3c6c5466b443ceb6bac0b0f626ac82.jpg)
我是初学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');
内容总结
以上是互联网集市为您收集整理的!Codeigniter无法调用PHPExcel全部内容,希望文章能够帮你解决!Codeigniter无法调用PHPExcel所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。