如何保存并生成Excel文件并保存在服务器中 [英] How to save and generate excel file and save in server

查看:113
本文介绍了如何保存并生成Excel文件并保存在服务器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须通过php生成zip文件,该文件中几乎没有简历和1个excel文件我成功添加了简历,但无法添加excel,因为该excel文件也是生成excel的php文件,因此我希望代码将该excel文件保存在服务器上,因此我可以在其zip文件中包括所有动态文件,因此我很困惑如何当有人单击下载的zip文件并在其中也获取了excel文件时,就会发生这种情况.

I've to generate zip file by php in that file there are few resume and 1 excel file I successfully add that resumes but unable to add excel because that excel file is also php file which generate excel so i want code to save that excel file on server so i can include in my zip file its all dynamic so i'm confused how can it happens when someone click on download zip file and get that excel file also in it.

推荐答案

首先,执行脚本以制作excel文件(将临时文件保存在某处)然后执行"zip"脚本

first, you execute your script that make the excel file (you save the temp file somewhere) and then you execute your "zip" script

如果无法同时合并两个脚本,则始终可以使用file_get_content()执行第一个脚本(必须在服务器上启用fopen):

if you cannot concat the two scripts in one, you always can execute the first one by using file_get_content() like that (fopen must be enabled on your server) :

$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();

这篇关于如何保存并生成Excel文件并保存在服务器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆