Jump to content

Generating txt file for download


_OwNeD.YoU_

Recommended Posts

Hi guys,

I was wondering if there is any way to generate a file for users to download.

 

I have text that a query grabs, i was wondering if there is anyway for it to be downloaded into a text file for download, but there are tons of them are would rather not have them actually stored on the server.

Link to comment
https://forums.phpfreaks.com/topic/135534-generating-txt-file-for-download/
Share on other sites

Here:

 

function download($file) 
{
	if(file_exists($file)) 
	{
    	header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
	}
}

yeaa its all stored in the database, having trouble get that to work though,

 

<?php

$file = "Hello World";

function download($file)

{

if(file_exists($file))

{

    header('Content-Description: File Transfer');

        header('Content-Type: application/octet-stream');

        header('Content-Disposition: attachment; filename='.basename($file));

        header('Content-Transfer-Encoding: binary');

        header('Expires: 0');

        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

        header('Pragma: public');

        header('Content-Length: ' . filesize($file));

        ob_clean();

        flush();

        readfile($file);

}

}

 

?>

 

thats what i just have for a test, $file is where the infomation is stored correct?

thanks again guys sorry for the late responce i was on vacation.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.