Posted By

LuckyShot on 10/11/09


Tagged

php header pdf attachment mp3


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

BrianCoyDesign
tspitzr


Customize a file download (songs, PDFs, etc.)


 / Published in: PHP
 

URL: http://luckyshot.es/blog/customize-a-download-with-php/

This code is really useful to download files (i.e. an mp3 file). It will tell the browser about the file type you’re about to download while also customizing the file name of it.

  1. header('Content-type: audio/mpeg');
  2. header('Content-Disposition: attachment; filename="'.$name.'.mp3"');
  3. readfile($link);
  4.  
  5. // We just need to provide the $name and $link variables for it to work.

Report this snippet  

You need to login to post a comment.