note 79419 added to function.header

From: Date: Mon, 26 Nov 2007 18:55:30 +0000
Subject: note 79419 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-132577@lists.php.net to get a copy of this message
What if you want to serve all .pdf files on your site without changing all the links to point to a php script? The solution is to use Apache .htaccess and mod_rewrite with the php script. [ .htaccess ] +======================================+ RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^(.+)\.pdf$ /cgi-bin/pdf.php?file=$1 [L,NC,QSA] +======================================+ [ PHP Script pdf.php ] +======================================+ if(!isset($_GET['file']))die('LOGGED! no file specified'); $file_path=$_SERVER['DOCUMENT_ROOT']. '/'.strip_tags(htmlentities($_GET['file'])).'.pdf'; if ($fp = fopen ($file_path, "r")) { $file_info = pathinfo($file_path); $file_name = $file_info["basename"]; $file_size = filesize($file_path); $file_extension = strtolower($file_info["extension"]); if($file_extension!='pdf') { die('LOGGED! bad extension'); } ob_start(); header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="'.$file_name.'"'); header("Content-length: $file_size"); ob_end_flush(); while(!feof($fp)) { $file_buffer = fread($fp, 2048); echo $file_buffer; } fclose($fp); exit; exit(); } else { die('LOGGED! bad file '.$file_path); } +======================================+ original article: http://www.askapache.com/htaccess/pdf-plugin-adobe.html ---- Server IP: 64.71.164.2 Probable Submitter: 24.172.164.205 ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- https://master.php.net/note/edit/79419 Del: integrated -- https://master.php.net/note/delete/79419/integrated Del: useless -- https://master.php.net/note/delete/79419/useless Del: bad code -- https://master.php.net/note/delete/79419/bad+code Del: spam -- https://master.php.net/note/delete/79419/spam Del: non-english -- https://master.php.net/note/delete/79419/non-english Del: in docs -- https://master.php.net/note/delete/79419/in+docs Del: other reasons-- https://master.php.net/note/delete/79419 Reject -- https://master.php.net/note/reject/79419 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132577) next »