hi
i have a longtext field in mysql.i want to write the data which is in longtext to a .doc file.so tat when the user clicks download all the data will get downloaded in a doc file
thanks in advance

dont write help as a question heading.try to type meaning full question

Member Avatar for langsor

Parts or all of this you might find useful

<?php

$path = 'test.doc';
if ( !is_file( $path ) ) exit;
$file = file_get_contents( $path );

header( 'Content-Type: application/msword' );
header( 'Content-Length: '.filesize( $path ) );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: attachment; filename='.basename( $path ) );
print $file;

?>

You can learn more at the PHP website documentation under the search "header"
http://us2.php.net/manual/en/function.header.php

Enjoy

hi
Thanks for your reply..........
consider that my variable $test contains the db content then please tell me how use this code.

Member Avatar for langsor

Since you have your doc data as a variable already you can skip the file_get_contents part and drop the Content-Length header since it's only a courtesy for the browser anyway and give the doc a name ...

<?php

$doc_name = 'mydoc.doc';

header( 'Content-Type: application/msword' );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: attachment; filename='.$doc_name );
print $test;

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.