I'm trying to save an excel file to a server, but what I really need is to send it as an email attachment, so I'm trying to store it in server and then to send it as an attachment. But I get an error with the browser, it says it cannot find the file path/to/file/sendExcell.php. Send excel php is the file that I'm launching in the browser and it's being launched if I comment $objWriter->save(dirname(__FILE__).'stats.xlsx');
or if I change it to this other line:
$objWritter->save('php://output')
This is the code:
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
// We'll be outputting an excel file
header('Content-Type: application/xlsx');
header('Content-Disposition: attachment;filename="stats.xlsx"');
header('Cache-Control: max-age=0');
ob_end_clean();
$objWriter->save(dirname(__FILE__).'stats.xlsx');
print_r('ok');die; //never prints
I also cannot save it this way:
$objWriter->save();
It prints a white screen (removing the headers) and with the headers it prints the same error (cannot find the file)
Maybe You have not permission. If you use Linux try chmod 777.
$objWriter->save ( getcwd ().'/stats.xlsx')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.