Tag Archive for serve

Serve PDF file with PHP

// pdfString is the *contents* of a file.
// to serve a file that exists on the file system, use readfile() instead of print $pdfString

header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($pdfString));
header('Content-Disposition: attachment; filename=' . 'pdf_dynamic.pdf');
ob_clean();
flush();
print $pdfString;
exit;

source

Optionally Serve Statically Compressed CSS & JS

# no weird non-ASCII quotes! Arg! They wasted an hour of time!
# info: <a href="http://www.bluehostforum.com/showthread.php?t=11402" >http://www.bluehostforum.com/showthread.php?t=11402</a>

Options +followsymlinks

<FilesMatch ".js.gz$">
ForceType text/javascript
Header set Content-Encoding: gzip
</FilesMatch>
<FilesMatch ".js$">
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*).js$ $1.js.gz [L]
ForceType text/javascript
</FilesMatch>

<FilesMatch ".css.gz$">
ForceType text/css
Header set Content-Encoding: gzip
</FilesMatch>
<FilesMatch ".css$">
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*).css$ $1.css.gz [L]
ForceType text/css
</FilesMatch>

source