![](/img/trans.png)
[英]PHP: How to save mysql to excel file to a directory and not prompt user to download
[英]how to save excel file in my local directory in php with out downloading
我正在 Cms 中工作,如果任何客戶單擊並保存他們應該在瀏覽器中下載的 excel 文件,同時另一個副本保存到我的服務器文件夾中。 以下編碼僅有助於為客戶下載我想知道如何在本地服務器中保存另一個副本
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="your_name.xls"');
header('Cache-Control: max-age=0');
提前致謝
標題實際上與在服務器上創建或保存文件無關。 標題只告訴瀏覽器如何解釋內容。
查看PHP Excel以獲得有關創建 Excel 文件的良好資源。
首先,您執行使 excel 文件(將臨時文件保存在某處)的腳本
$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);
使用絕對路徑添加您的文件名
要么
使用PHPExcel ,你可以像下面這樣使用
$objWriter->save('nameoffile.xls');
希望這能解決你的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.