Data export to excel & save directly to the directory (folder)

霸气de小男生 提交于 2019-12-11 10:01:34

问题


Currently on clicking on export user is prompt a box to save/open the export excel file to their system , though what i want is when user click on export/send data , the data get exported & save to the server on specific folder & later which I mail that file to the user as an attachment.

Did I have to make any change in my header for the same ?

For ref below is the header from my export excel library:

  header("Content-type: application/vnd.ms-excel"); 
  header("Content-Disposition: attachment; filename=$this->filename"); 
  header("Pragma: no-cache"); 
  header("Expires: 0"); 
  print "$header\n$data"; 

Thanks in advance.


回答1:


The only thing you really need to do is save the Excel contents to disk on your server, you can also remove those headers completely as they are only needed when outputting the data to the browser.

When you mail the user, simply attach the file and send.

It should be pretty straight forward.

EDIT:

To save the excel file:

file_put_contents('<your file name>', '<your file contents>');

The content can be any string, so if you have the excel file contents in a variable, simple put it there.

The file name can be a relative or absolute path.



来源:https://stackoverflow.com/questions/8890300/data-export-to-excel-save-directly-to-the-directory-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!