PHP read-out PDF download on Web

Source: Internet
Author: User

<?php//represents the application header (' Content-type:application/pdf ') that invokes the text type as PDF;//This can be downloaded from the download page (' Content-disposition: Attachment Filename= "Downloaded.pdf");//can read out Pdfreadfile (' original.pdf '); >

  

To implement various file download methods:

<?php $file = "N1. PDF ";d ownloadfile ($file), function DownloadFile ($fullPath) {//must be fresh the start if (Headers_sent ()) Die (' Head   ERs Sent ');   Required for some browsers if (Ini_get (' zlib.output_compression ')) ini_set (' zlib.output_compression ', ' Off ');   File Exists?     if (file_exists ($fullPath)) {//Parse info/get Extension $fsize = filesize ($fullPath);     $path _parts = PathInfo ($fullPath);         $ext = Strtolower ($path _parts["extension"]);       Determine Content Type switch ($ext) {case "PDF": $ctype = "Application/pdf"; Case "EXE": $ctype = "Application/octet-stream";       Break Case "Zip": $ctype = "Application/zip";       Break Case "Doc": $ctype = "Application/msword";       Break Case "xls": $ctype = "application/vnd.ms-excel";       Break Case "ppt": $ctype = "Application/vnd.ms-powerpoint";       Break Case "gif": $ctype = "Image/gif";       Break Case "png": $ctype = "Image/png";       Break Case "JPEG": Case "JPG ": $ctype =" image/jpg ";       Break     Default: $ctype = "Application/force-download"; } header ("Pragma:public");     Required header ("expires:0");     Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0"); Header ("Cache-control:private", false);     Required for certain browsers header ("Content-type: $ctype"); Header ("content-disposition:attachment; Filename=\ "". BaseName ($fullPath). "     \";" );     Header ("Content-transfer-encoding:binary");     Header ("Content-length:". $fsize);     Ob_clean ();     Flush ();   ReadFile ($fullPath); } else die (' File not Found '); }?>

  

PHP read-out PDF download on Web

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.