dszpyf4859 2015-04-07 13:58
浏览 226

来自php:// memory的PHPExcel_IOFactory :: load()

I'm trying to load an excel file from 'php://memory' stream.

Here's my code:

$path = 'http://<server>/test.xls';

$temp_file = fopen('php://memory', 'w+');

$file_contents = file_get_contents($path);
fwrite($temp_file, $file_contents);

$objPHPExcel = PHPExcel_IOFactory::load($temp_file);
fclose($temp_file);

I'm getting these errors:

PHP Warning:  pathinfo() expects parameter 1 to be string, resource given in /var/resources/classes/PHPExcel/IOFactory.php on line 224
PHP Warning:  file_exists() expects parameter 1 to be a valid path, resource given in /var/resources/classes/PHPExcel/Reader/Excel2007.php on line 81
PHP Fatal error:  Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open Resource id #15 for reading! File does not exist.' in /var/resources/classes/PHPExcel/Reader/Excel2007.php:82
Stack trace:
#0 /var/resources/classes/PHPExcel/IOFactory.php(280): PHPExcel_Reader_Excel2007->canRead(Resource id #15)
#1 /var/resources/classes/PHPExcel/IOFactory.php(191): PHPExcel_IOFactory::createReaderForFile(Resource id #15)
#2 /var/www/syncDB.php(113): PHPExcel_IOFactory::load(Resource id #15)
#3 {main}
  thrown in /var/resources/classes/PHPExcel/Reader/Excel2007.php on line 82

I don't want to write the .xls file to disk. I tried to use tmpfile(), but I still get the same problem. Is there something wrong with my code? Or do I inevitably need to pass the path of a file on disk for 'PHPExcel_IOFactory::load' to work with?

It maybe worth mentioning here that 'Mark Baker's' answer on this SO question suggests that using php://memory should be possible.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)