Jump to content
xisto Community
HannahI

Rtf Generation [solved]

Recommended Posts

I am writing I script to generate RTF files. But the problem is that as soon as I hit the open button, my texteditor occurs an error. Can someone please fix my code?
Here it is:

<div class="page" style="background:white;"> <form action="?" method="post"> <select name="font"> <option value="Arial">Arial</option> <option value="Times">Times New Roman</option> </select> <br /> <textarea name="text"> Type Here </textarea> <input type="hidden" name="done" value="1"> <br/> <input type="submit"> </form> <?php $text = ' {\rtf\ansi\ansicpg\1252\cocoartf1038\cocoasubrtf250 {\fontb1\f0\fswiss\fcharset() '.$_POST['font'].';} {\colorb1;\red255\green255\blue255;} \margl440\margl440\vieww9000\veiwh8400\viewkind() \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6489\tx7200\tx7920\tx8640\ql\qnatural\pardirnatutal \f0\fs24 \cf() '.$_POST['text'].' } '; if($_POST['done'] == 1) { $fp = fopen('writetest.rtf','w+'); fwrite($fp,$text); fclose($fp); echo '<a href="writetest.rtf">Download</a>'; } ?> </div>
Thanks,
-Hannah
Edited by yordan
added "solved" (see edit history)

Share this post


Link to post
Share on other sites

Hi!I'm unable to follow your description of the problem, so if I am misinterpreting your case, do let me know.My understanding is that when you run the script on a web server by accessing it from a web browser, a text editor or word processor opens complaining about an error. If this is what you are experiencing, you might not have the the file created with a .php extension, the start and end HTML tags are missing in the document, or the web server isn't configured correctly to process PHP scripts. When the web server doesn't recognize the file type that you are requesting, it sends the file as-is to your browser, which then uses Windows to determine which program is appropriate to open the file if it is not a web page or image (although in some cases, images are opened using an external program too). The editor you are using might expect the file to be in a specific format, which is why it reports an error.It would help if you can provide more information about the problem you are experiencing. When you do get past the problem you are experiencing, I see a possible file permissions issue with writing to a file on the disk (using the fopen, fwrite, and fclose function calls).

Share this post


Link to post
Share on other sites

Sorry if a misplaced my problem. I use my online rtf generater like a normally would. I hit the download button. My browser shows me it was downloaded succussfully. I opened up my text editor and it didn't work. :)

Share this post


Link to post
Share on other sites

Sorry if a misplaced my problem. I use my online rtf generater like a normally would. I hit the download button. My browser shows me it was downloaded succussfully. I opened up my text editor and it didn't work. :)

Did you try to directly generate your writetest.rtf file, ftp download it to your pc and open it with WordPad or with ODT in order to check that it's a regular rtf file ?

Share this post


Link to post
Share on other sites

I've gone through the code, and normally I would agree with the backslashes statement however it's not in double speech marks so that's not the case here. It's actually a problem with the rtf formatting, I've gone through and updated it like so, note the value of the dropdown is now the f reference inside the rtf code and have pre-defined Times New Roman (f1) and Arial (f0), this should work fine now and have had no problems in my rtf reader (wordpad).

Also another problem was the initial new line after the first speech mark, it cause other readers to consider the whole thing as text instead of rich text.

<div class="page" style="background:white;"><form action="?" method="post"><select name="font"><option value="1">Arial</option><option value="0">Times New Roman</option></select> <br /><textarea name="text">Type Here</textarea><input type="hidden" name="done" value="1"> <br/><input type="submit"></form><?php$text = '{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\fswiss\fcharset0 Arial;}}{\colortbl;\red255\green255\blue255;}\viewkind4\uc1\pard\cf'.$_POST['font'].'\f'.$_POST['font'].'\fs24 '.$_POST['text'].'\cf'.$_POST['font'].'\f'.$_POST['font'].'\par}';if($_POST['done'] == 1) {$fp = fopen('writetest.rtf','w+');fwrite($fp,$text);fclose($fp);echo '<a href="writetest.rtf">Download</a>';}?></div>

Oh yeah, and also you had a slash between ansicpg and 1252 which was the main cause of the error
Edited by 8ennett (see edit history)

Share this post


Link to post
Share on other sites

I'm just wondering actually, how come you want generate the file in rtf format? I haven't written rtf headers for a while so it was fun ammending this code. But yeah, in what context would this script be exporting rich text?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.