I also want to be able to format the extension, for instance to add .xml or something to it. I know how to download a blob file, with all the filesize, name etc. (changing headers), but do I need the same for just a text file?
There are several ways to accomplish this. I would setup a table 'files' like this:
CREATE TABLE 'files' (
id INT( 5 ) NOT NULL AUTO_INCREMENT,
extension VARCHAR( 4 ) NOT NULL DEFAULT 'txt',
content_type VARCHAR( 20 ) NOT NULL DEFAULT 'text/plain',
data VARCHAR( 100000 ) NOT NULL,
PRIMARY KEY (id) );
download.php code:
$id = mysqli_real_escape_string($link, $_GET['id']);
$SELECT = "SELECT * FROM files WHERE id = $id";
$result = mysqli_query($SELECT, $link);
$result = mysqli_fetch_assoc($result);
header("content-type: $result['content_type']");
echo $result['data'];
html:
<a href="download.php?id=$_GET['id']">download file</a>