Answer the question
In order to leave comments, you need to log in
How to create a temporary php download file?
Help me please.
The site has a base with a history of visits. I need the user to be able to download their database.
That is, I need to create a temporary file and write data from mysql to it and give the file for download.
How to implement this with php?
It is desirable to answer with an example, since I could not find the necessary information on the Internet about this.
Answer the question
In order to leave comments, you need to log in
Perhaps it will be easier to generate a file with a log on the fly directly from the script and immediately download it
. This will give you more control in terms of security, since you can check authorization beforehand, etc. and you don’t have to worry about storing, deleting a bunch of files
<?php
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=history.txt");
//делаем запрос к БД на получение данных
//выводим нужные данные через echo
file_put_contents()
where you pass the data and the file name to save Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question