php教程 生成word文檔並下載代碼
include("include/conn_mysql教程.php");
$id=$_GET["id"];
$sql="select * from down where id=$id ";
$result=mysql_query($sql);
$row=mysql_fetch_row($result);
$file2=$row["upload"];
function downFile($sFilePath)
{
if(file_exists($sFilePath)){
$aFilePath=explode("/",str_replace("","/",$sFilePath),$sFilePath);
$sFileName=$aFilePath[count($aFilePath)-1];
$nFileSize=filesize ($sFilePath);
header ("Content-Disposition: attachment; filename=" .basename($sFileName) );
header ("Content-Length: " . $nFileSize);
header ("Content-type: application/octet-stream");
mb_convert_encoding(readfile($sFilePath),"utf-8","GB2312");
}
else
{
echo("文件不存在!");
}
}
downFile($file2);
/*
這個生成word生成文檔程序是從mysql數據庫教程讀取數據保存文件再用header來發送給浏覽器。
*/