Posted By

LuckyShot on 10/11/09


php header pdf attachment mp3

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


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

 / Published in: 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);
  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.