If you have used my WordPress readme generator you would have noticed that I have a “Save As” button, which when pressed allows you to download the file which was just generated by the PHP code. (In most browsers this opens the save file as dialog box)
Recently one of the readers of my blog asked me how to do this in PHP and I was about to send him the code snippet. But then I thought of writing a blog article so that it will be useful for others as well.
So here we go.
The code is mostly self explanatory. The important part in the above code snippet is the “content Disposition” header.
Also since we are sending headers to the browser, we should not have started the output before this code executes. Otherwise we might get a “header already sent” error.
- Easy Retweet plugin now supports Google Analytics tracking
- Creating new pages in WordPress through code
- Developing WordPress Plugins in Github
- Completely rewrote WP-IRC Plugin
- WordPress Plugin to add Foss.in badge
- Posts By Tag Plugin now supports excluding current post
- Started tracking time spend on my pet projects
- Bulk Delete Plugin now supports deleting by permalink
- Adopted Cron debug log WordPress Plugin
- Phishing attempts to get your wordpress.org password