<?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