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

/ Published in: PHP
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.