PHPSReadSheet-文件不存在
我正在做一个项目,我需要阅读一个表格中发送的excel文件,然后从中提取数据。我正试图使用Phpspreadsheet库,但Phpspreadsheet库似乎无法识别该文件,并抛出一个错误:该文件不存在PHPSReadSheet-文件不存在,php,codeigniter,codeigniter-3,phpspreadsheet,Php,Codeigniter,Codeigniter 3,Phpspreadsheet,我正在做一个项目,我需要阅读一个表格中发送的excel文件,然后从中提取数据。我正试图使用Phpspreadsheet库,但Phpspreadsheet库似乎无法识别该文件,并抛出一个错误:该文件不存在 $product_serial = $this->input->post('product_serial'); $excelFilePath = base_url().'userfiles/product/excelfiles/'.$product_serial;
$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“不存在
我已经在上面的位置检查了文件,文件确实存在 Codeigniter从文件系统读取文件,因此必须使用路径而不是URL 实际上,您正在使用URL:
base_url().'userfiles/product/excelfiles/'.$product_serial;
您需要从FCPATH
FCPATH.'userfiles/product/excelfiles/'.$product_serial;
有关代码点火器常数的更多信息,请访问以下链接
正如Cesare的回答所述,URL和路径之间存在差异。访问内部资源时,应始终使用路径。尽管它们看起来可以互换,但实际上并非如此