Php tutorials generate Word documents and download code
Include ("include/conn_mysql tutorial. 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 ("The file does not exist! ");
}
}
DownFile ($ file2 );
/*
This word generation document program reads data from the mysql database tutorial and saves the file and sends it to the browser with the header.
*/