PHP Streaming MP3

Here’s what did the trick. $dir = dirname($_SERVER[‘DOCUMENT_ROOT’]).”/protected_content”; $filename = $_GET[‘file’]; $file = $dir.”https://stackoverflow.com/”.$filename; $extension = “mp3”; $mime_type = “audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3”; if(file_exists($file)){ header(‘Content-type: {$mime_type}’); header(‘Content-length: ‘ . filesize($file)); header(‘Content-Disposition: filename=”‘ . $filename); header(‘X-Pad: avoid browser bug’); header(‘Cache-Control: no-cache’); readfile($file); }else{ header(“HTTP/1.0 404 Not Found”); }

How to export / dump a MySql table into a text file including the field names (aka headers or column names)

Piping the query to the commandline client outputs a tab separated list with the column names as the first line $ echo “select * from surveys limit 5” | mysql -uroot -pGandalf surveys phone param1 param2 param3 param4 p0 p1 p2 p3 audio4 code time XXXXXXXXX 2008-07-02 11:17:23 XXXXXXXX SAT – – – – – … Read more

vs.

<header> is one of several new tags in HTML5 that are supposed to replace <div> for some specific situations. In particular, the “header” part of your page – whatever that is, usually the part that would be wrapped in <div class=”header”> – in HTML5 you should use <header> instead. Chapter 3 of Dive into HTML5 … Read more

Precedence: header in email

There is a RFC 3834 dedicated for automated email responses. In short, it recommends: Send auto-responses only to address contained in the Return-Path header of an incoming message, if it is valid email address. Particularly “<>” (null address) in the Return-Path of the message means that auto-responses must not be sent for this message. When … Read more

PHP get pdf file from base64 encoded data string

Try this piece of code $pdf_base64 = “base64pdf.txt”; //Get File content from txt file $pdf_base64_handler = fopen($pdf_base64,’r’); $pdf_content = fread ($pdf_base64_handler,filesize($pdf_base64)); fclose ($pdf_base64_handler); //Decode pdf content $pdf_decoded = base64_decode ($pdf_content); //Write data back to pdf file $pdf = fopen (‘test.pdf’,’w’); fwrite ($pdf,$pdf_decoded); //close output file fclose ($pdf); echo ‘Done’;

How to set response header in JAX-RS so that user sees download popup for Excel?

You don’t need HttpServletResponse to set a header on the response. You can do it using javax.ws.rs.core.Response. Just make your method to return Response instead of entity: return Response.ok(entity).header(“Content-Disposition”, “attachment; filename=\”” + fileName + “\””).build() If you still want to use HttpServletResponse you can get it either injected to one of the class fields, or … Read more