Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将excelsheet数据加载到codeigniter中的db中_Php_Codeigniter - Fatal编程技术网

Php 将excelsheet数据加载到codeigniter中的db中

Php 将excelsheet数据加载到codeigniter中的db中,php,codeigniter,Php,Codeigniter,我需要使用codeigiter将excelsheet数据加载到数据库中。为此,我尝试了这种编码 function excel_data() { //include 'PHPExcel/IOFactory.php'; $this->load->library("PHPExcel"); $inputFileName = '../first_data.xls'; // Read your Excel workbook try { $inputFileType =

我需要使用codeigiter将excelsheet数据加载到数据库中。为此,我尝试了这种编码

function excel_data()
    {
//include 'PHPExcel/IOFactory.php';
  $this->load->library("PHPExcel");
 $inputFileName = '../first_data.xls';


//  Read your Excel workbook
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}

//  Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0); 
$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestColumn();

//  Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++){ 
    //  Read a row of data into an array
    $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
    //  Insert row data array into your database of choice here
    // $this->User_model->add_data($rowData);
}

 }
函数excel\u data()
{
//包括“PHPExcel/IOFactory.php”;
$this->load->library(“PHPExcel”);
$inputFileName='../first_data.xls';
//阅读您的Excel工作簿
试一试{
$inputFileType=PHPExcel\u IOFactory::identify($inputFileName);
$objReader=PHPExcel\u IOFactory::createReader($inputFileType);
$objPHPExcel=$objReader->load($inputFileName);
}捕获(例外$e){
die('Error loading file'.pathinfo($inputFileName,pathinfo_BASENAME)。'”:'。$e->getMessage());
}
//获取工作表维度
$sheet=$objPHPExcel->getSheet(0);
$highestRow=$sheet->getHighestRow();
$highestColumn=$sheet->getHighestColumn();
//依次遍历工作表的每一行
对于($row=1;$row RANGETORARRAY('A'.$row'.:'。$HIGHEST COLUMN.$row),
无效的
是的,
假);
//在此处将行数据数组插入所选数据库
//$this->User\u model->add\u data($rowData);
}
}
执行iam时出现此错误“加载文件“first_data.xls”时出错”:无法打开../first_data.xls进行读取!文件不存在。“我的编码有什么问题?”


我的错误是什么。有人知道吗?

…路径正确吗?文件存在吗?它是否具有正确的权限?我已在控制器文件之外的应用程序中提供了xls文件。在这种情况下,我认为您必须使用文件的绝对文件系统路径。例如C:\somedir\thefile.xls不要将文件放在应用程序中在上,您可以在根文件夹(应用程序外部)
assets
中创建一个目录,并将其放置在中,您可以作为
assets/filename.xls