如何保存和生成excel文件,并保存在服务器


How to save and generate excel file and save in server

我必须通过php生成zip文件,在该文件中有几个简历和一个excel文件我成功地添加了简历,但无法添加excel,因为excel文件也是php文件,它生成excel,所以我想要代码保存excel文件在服务器上,所以我可以在我的zip文件中包含它,它都是动态的,所以我很困惑,当有人点击下载zip文件,并得到excel文件也在其中,这是怎么发生的

首先,执行生成excel文件的脚本(将临时文件保存在某个地方)然后执行zip脚本

如果不能将两个脚本连接在一起,则可以使用file_get_content()执行第一个脚本,如下所示(服务器上必须启用fopen):

$my_excel_content = file_get_content("http://myserver/make_excel.php?parameters=...");
$my_excel_filename = "/tmp/".md5(session_id().microtime(TRUE)).".xls";
file_put_content($my_excel_filename,$my_excel_content);
$zip = new ZipArchive();
if ( $zip->open("myzip.zip", ZIPARCHIVE::CREATE) ) {
    $zip->addFile($my_excel_filename , "the-excel-file.xls");
}
$zip->close();