Question: How to force a download dialog box to appear when clicking a download link/button, instead of displaying it in the browser?
Answer: You do not need to create or write a file for a text file, or html file, or php file, or even image file. All you need to do is think of a name for the file, make a link or button and point them to this script below:
$filename = “filename.txt”;
$filecontent = “This is the text that will be written in the filename.txt. It could be anything in here, including the encoded characters of an image file.”;
header(“Content-disposition: attachment; filename=”.$filename);
That’s it. Easy, right? Good Luck!