A
A
Asjacker2020-02-25 22:35:18
PHP
Asjacker, 2020-02-25 22:35:18

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

1 answer(s)
N
nokimaro, 2020-02-25
@Asjacker

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

If you still want to create files and write data to them, then use file_put_contents()where you pass the data and the file name to save
https://www.php.net/manual/ru/function.file-put-co...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question