将mysql单元格转换为文本文件,允许用户下载,然后删除文本文件

how can i make a function in php that, when a link was clicked it would download a certain cell in a mySQL table and allow the user to download it as a .txt file? When the download is complete, the file is deleted.

I don't think you'd need to create/delete any files...

Say you have a link on your page:

<a href="download.php?id=whatever">Download this as a txt file</a>

I'm not sure how you're identifying the cells that the user wants to download, but I'll trust that you're doing it securely and efficiently.

Somehow, you have the table name, the row, and the column of the MySQL cell. So you just do a simple query...

$result = mysqli_query('select the cell', $your_db);
$result = mysqli_fetch_assoc($result);
$result = $result['cell_name'];

This gives you the value of that cell as a simple PHP variable. Now all you need to do is output it to the user:

header('content-type: text/plain');
echo $result;

That should print the value of the cell to the screen, as simple text. The user could then save the page. :D

Edit - Force Download

I haven't tested this, but the basic idea would be to add some more headers:

header('content-type: text/plain');
header('Content-Disposition: attachment; filename=whatever.txt');
header('Pragma: no-cache');
echo $result;

Don't create a file in the first place. Force a download, and send the text.

$text = mysql_query("SELECT content FROM texts WHERE id = $id");
$text = mysql_fetch_assoc($text);
$text = $text["content"];

header("Content-type: text/plain");
header("Content-disposition: attachment;filename=\"filename.txt\"");
header("Content-Length: ".strlen($text)); 

echo($text);