我在一个项目中工作,我需要读取一个表格中发送的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“不存在
我已经检查了上述位置的文件,该文件确实存在!
发布于 2020-09-09 22:52:21
Codeigniter从文件系统中读取文件,因此您必须使用路径而不是URL。
实际上,您使用的是URL:
base_url().'userfiles/product/excelfiles/'.$product_serial;您需要从FCPATH构建您的路径
FCPATH.'userfiles/product/excelfiles/'.$product_serial;有关Code触发器常量的更多信息,请访问以下链接
https://codeigniter.com/user_guide/general/common_functions.html?#global-constants
Codeigniter - dynamically getting relative/absolute path outside of application folder
https://stackoverflow.com/questions/63814088
复制相似问题