PHP generates Word documents and downloads code

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code content file mysql_query php php tutorial programming select

PHP Tutorial Generate Word document 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);
  $file 2= $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 ("file does not exist!");
  }
}

Downfile ($file 2);
/*
This generates a Word generation document program that reads data from a MySQL database tutorial and then sends the header to the browser.
*/
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.