Home > php教程 > php手册 > body text

php 生成word文档并下载代码

WBOY
Release: 2016-06-13 11:23:50
Original
1798 people have browsed it

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来发送给浏览器。
*/


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template