Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.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
PHPSReadSheet-文件不存在_Php_Codeigniter_Codeigniter 3_Phpspreadsheet - Fatal编程技术网

PHPSReadSheet-文件不存在

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;

我正在做一个项目,我需要阅读一个表格中发送的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“不存在


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

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

实际上,您正在使用URL:

base_url().'userfiles/product/excelfiles/'.$product_serial;
您需要从
FCPATH

FCPATH.'userfiles/product/excelfiles/'.$product_serial;
有关代码点火器常数的更多信息,请访问以下链接


正如Cesare的回答所述,URL和路径之间存在差异。访问内部资源时,应始终使用路径。尽管它们看起来可以互换,但实际上并非如此