把网页转换成doc 格式的文件,方便用户下载PHP 方法
//生成word文档
function cword($id,$data,$fileName='')
{
if(empty($data)) return '';
$data = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">'.$data.'</html>';
$dir = "./Uploads/serie/teach/";
if(!file_exists($dir)) mkdir($dir,0777,true);
if(empty($fileName))
{
$fileName=$dir.$id.'.doc';
}
else
{
$fileName =$dir.$fileName.'.doc';
}
$writefile = fopen($fileName,'wb') or die("创建文件失败"); //wb以二进制写入
fwrite($writefile,$data);
fclose($writefile);
return $fileName;
}