作者:烂在心底 | 来源:互联网 | 2022-12-17 16:58
php教程生成word文档并下载代码include("includeconn_php教程.php"); $id$_GET["id"
php教程 生成word文档并下载代码
include("include/conn_php教程.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("php教程);
$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生成文档程序是从mysqlphp教程读取数据保存文件再用header来发送给浏览器。
*/