0

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)

2 Answers 2

2

Maybe You have not permission. If you use Linux try chmod 777.

Sign up to request clarification or add additional context in comments.

2 Comments

And, even if that helped, change it to something more restrictive afterwards immediately. You don't want 777 directories in a production environment, unless you do so on purpose. ;-)
For production usually use 755 or 644 permission
0
$objWriter->save ( getcwd ().'/stats.xlsx')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.