PHP - export function output directly to a download file

PHP - export function output directly to a download file

Hello,

in PHP Nette, I would like to export $ rows records from the function below directly to a file, without displaying the results. Just for the browser to start downloading the result and not display it. The function is, for example, as follows:


public function actionExport($d_id)
{
$rows = $this->modelExport->getExport($d_id);
}


REPLY


Hi,

use the header as follows:


public function actionExport($d_id)
{
$rows = $this->modelExport->getExport($d_id);

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename='export.txt');
foreach ($rows as $r) {
echo "$r\n";
}
exit();
}


Description - The loop goes through $rows and saves them as an export.txt file.

Související obsah

php

programovani

loop

file

export

Komentáře

Vaše reakce na PHP - export výstupu funkce rovnou do souboru ke stažení

Reference

Podívejte se na naše reference

Prohlédnout

Aplikace

Podívejte se na naše aplikace

Prohlédnout

Co umíme?

Podívejte se co umíme

Prohlédnout

Co umíme?

Vytváříme sofistikované aplikace pro náročné

Od webových aplikací přes android až po převodové můstky či složité informační systémy.

Podívejte se k nám

Máte ještě čas? Podívejte se na další rubriky

Tento web používá soubory cookie. Dalším procházením tohoto webu vyjadřujete souhlas s jejich používáním.. Více informací zde.