【发布时间】:2020-09-09 14:43:58
【问题描述】:
我正在做一个项目,我需要读取以表格形式发送的 excel 文件,然后从中提取数据。我正在尝试使用 Phpspreadsheet 库,但 Phpspreadsheet 库似乎无法识别该文件并引发错误:该文件不存在。
$product_serial = $this->input->post('product_serial');
$excelFilePath = base_url().'userfiles/product/excelfiles/'.$product_serial;
try {
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($excelFilePath);
$spreadSheet = $reader->load($excelFilePath);
$dataAsAssocArray = $spreadSheet->getActiveSheet()->toArray();
}
catch (\Exception $exception){
echo $exception->getMessage();
}
错误:文件“http://localhost:8000/userfiles/product/excelfiles/452260670768Untitledspreadsheet.xlsx”不存在
我已经检查了上述位置的文件,该文件确实存在!
【问题讨论】:
-
正如 Cesare 的回答所述,URL 和路径之间存在差异。访问内部资源时,您应该始终使用路径。尽管它们看起来可以互换,但它们不是
标签: php codeigniter codeigniter-3 phpspreadsheet