首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Phpspreadsheet -文件不存在

Phpspreadsheet -文件不存在
EN

Stack Overflow用户
提问于 2020-09-09 22:43:59
回答 1查看 901关注 0票数 0

我在一个项目中工作,我需要读取一个表格中发送的excel文件,然后从中提取数据。我正在尝试使用Phpspreadsheet库,但Phpspreadsheet库似乎无法识别该文件,并抛出错误:该文件不存在。

代码语言:javascript
复制
$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“不存在

我已经检查了上述位置的文件,该文件确实存在!

EN

回答 1

Stack Overflow用户

发布于 2020-09-09 22:52:21

Codeigniter从文件系统中读取文件,因此您必须使用路径而不是URL。

实际上,您使用的是URL:

代码语言:javascript
复制
base_url().'userfiles/product/excelfiles/'.$product_serial;

您需要从FCPATH构建您的路径

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63814088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档