PHPExcel icon indicating copy to clipboard operation
PHPExcel copied to clipboard

Could not open php://output for writing

Open kabeza opened this issue 10 years ago • 1 comments

Hi When using $objWriter->save('php://output'); in shared hosting environment, I'm getting an exception when trying to generate file and send to user's browser for download.

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');

Uncaught exception 'PHPExcel_Writer_Exception' with message 'Could not open php://output for writing.' in third_party/PHPExcel/Writer/Excel2007.php:241 Stack trace: #0

Which folder should I give chmod 777 ? tmp? Thanks

kabeza avatar Oct 28 '15 15:10 kabeza

This coursed by php process do not have permission to read the OS temp dir. To solve the problem, call sys_get_temp_dir() function to get the real OS temp dir. the path is a string may like 'C:\Users\ADMINI~1\AppData\Local\Temp'. Then copy this path and open php.init file, find this line open_basedir="xxxx", and add the path you got to the bottom of the line. that's all

chguoxi avatar Jul 25 '18 07:07 chguoxi