I find alot of questions regarding how to prompt a user for a PHP download. I've
created a way to easily make this happen with just two lines of code. I have not
found a better way to do this. This is too simple!
Step 01.
The first thing you need to do is add your PHP code to a simple text file, which
can be any name. I will use test.txt as an example.
Step 02.
You need to place the following code in a new PHP file, which can be called anything
you want. I will use script.php as an example.
<?php
/**
* Downloadable PHP code
* Created by: Josh (TRUSTAbyss)
*
* Provided by: trustabyss.com
*/
header("Content-Type: application/force-download");
// Add the path to your text file
@readfile("test.txt");
?>
Step 03:
Now all you have to do is put the PHP and text file in your htdocs. Now when
you link to the script.php file, you will get a download prompt. Hopefully this
will help someone with the distribution of their PHP scripts.
Note: This does not allow you to save processed PHP code. Only the original
code you've written locally will be saved as a download.