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.