This topic is locked

How Do I Save The Contents Of A Field To A Text Or Doc File?

3/26/2013 11:59:02 PM
PHPRunner General questions
K
karmacomposer author

I am creating a story site for my son and I have a client that also needs this same function.
I added a button to the edit page of the STORIES table and added this code:



$_GET['storytext']

$fp = fopen("story.doc", 'w+');

fwrite($fp, $_POST['storytext']);

fclose($fp);


The field's name is storytext in the table Stories.
I want the user to press the SAVE DOC FILE button and it then saves the contents of the field to a text or doc file

on the user's computer.
I found the above code on the internet, but it does not work. Theoretically, you can issue the fwrite command and it will write to

a file. There are some necessary headers that have to be coded somewhere, but not sure where. Here are the headers:



header("Content-Type: application/vnd.ms-word");

header("Expires: 0");

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

header("content-disposition: attachment;filename=story.doc");


Any advice is appreciated.
Mike

C
cgphp 3/27/2013

Make sure you have write permissions on that directory. Enable firebug and check if you get errors.