PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 4, 2022

[FIXED] How to save excel file on server with php?

 October 04, 2022     php, phpexcel     No comments   

Issue

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)


Solution

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



Answered By - Vahe Galstyan
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing