html
模板下载: <a href="#" id="download" >模板</a>
js
<script>
$("#download").click(function () {
var fileName="sku导入模板";
var list=new Array(["帐号名称"],["SellerSku"],["FNSKU"],["公司内部SKU"],["ASIN"],["title"],["FBA首次入库时间"]);
var list1= new Array(["account"],["SellerSku"],["FNSKU"],["insku"],["asin"],["title"],["2017-01-01"]);
window.location.href ="Inbound/Prepareneeds/download?"+"&fileName="+fileName+"&list="+list+"&list1="+list1;
});
</script>
php
public function download()
{
set_time_limit(0);
ini_set('memory_limit','2048M');
//为fputcsv()函数打开文件句柄
$outPut = fopen('php://output','w') or die("can't open php://output");
//告诉浏览器这个是一个csv文件
$fileName = $_GET['fileName'];
header("Content-Type: application/csv");
header("Content-Disposition: attachment;filename=$fileName.csv");
//输出表头
$tableHead = explode(',',$_GET['list']);
fputcsv($outPut,$tableHead);
$body = explode(',',$_GET['list1']);
fputcsv($outPut, $body);
//关闭文件句柄
fclose($outPut) or die("can't close php://output");
exit;
}
ok
就这样