Customize a download with PHP

by
on August 30, 2008
(0 min read)

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:

header('Content-type: audio/mpeg');
header('Content-Disposition: attachment; filename="'.$name.'.mp3"');
readfile($link);

Simple Cloud Hosting Built for Developers

Now we just need to provide the $name and $link variables for it to work.

This piece of code was borrowed from Michael Pardo. Thank you!

Did you enjoy this article?

Buy the author a coffee 🤗☕

No comments yet

Follow me for cool new products and interesting findings on graphic design, web development, marketing, startups, life and humor.


/*Twitter*/ !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs"); /*Facebook*/ (function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=28624667607";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk')); /*Google+*/ window.___gcfg = {lang: 'en-GB'};(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;po.src = 'https://apis.google.com/js/plusone.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);})();
Airbnb 30€ discount