Save dynamic data to text file
am 12.11.2007 10:37:23 von WayneBurrowsCan I save dynamically created data to a text file on the client's
machine?
Preferrably in a user named file through a save dialog box.
Thanks
Wayne
Can I save dynamically created data to a text file on the client's
machine?
Preferrably in a user named file through a save dialog box.
Thanks
Wayne
WayneBurrows wrote:
> Can I save dynamically created data to a text file on the client's
> machine?
>
> Preferrably in a user named file through a save dialog box.
Hi,
You cannot directly save a file on the clients disk (luckily).
But you can offer a download of the file.
Just create a PHP script that sets the right headers, and produces the
output.
Have a look at the header function.
You will find a few examples and also a few usercontributed notes:
http://nl.php.net/header
Regards,
Erwin Moller
>
> Thanks
>
> Wayne
>
On Nov 12, 11:37 am, WayneBurrows
> Can I save dynamically created data to a text file on the client's
> machine?
>
> Preferrably in a user named file through a save dialog box.
>
> Thanks
>
> Wayne
$string = "bla bla bla"; // file content
$filename='some.txt';
$mime_type = (PMA_USR_BROWSER_AGENT == 'IE' ||
PMA_USR_BROWSER_AGENT == 'OPERA')
? 'application/octetstream'
: 'application/octet-stream';
header('Content-Type: ' . $mime_type);
if (PMA_USR_BROWSER_AGENT == 'IE')
{
header('Content-Disposition: inline; filename="' . $filename .
'"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-
check=0');
header('Pragma: public');
print $string;
} else {
header('Content-Disposition: attachment; filename="' .
$filename . '.' . $ext . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
print $string;
};
?>
if you'll need any explanations - tell me.