Create and "Save As" text file automatically using PHP -


so, trying export data database , have automatically prompt user save data has text file. here code:

$datefile = rand(10000000, 99999999).".txt"; $datastring = "my data here blah blah blah"; $fwrite = fopen($datefile,"w"); $wrote = fwrite($fwrite, $datastring); fclose($fwrite); header('content-type: application/text'); header('content-disposition: attachment; filename="'.$datefile); 

this seems work in small ways - text file is, indeed, being created in same directory (as php page), , file seems open... no data in it. if navigate text file , open it, can see string there. doesn't open file automatically. doing wrong?

edit: fwiw don't need file saved server per se, thought quick , easy way of getting "save as" text file created... if can think of way of doing without saving server, good, too.

have tried sending content directly?

header('content-type: application/text'); header('content-disposition: attachment; filename="'.$datefile.'"'); echo $datastring; 

it's maybe simple way, might solution need.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -