Is it possible to display an RTF file inside a web page using PHP?

后端 未结 7 1726
长情又很酷
长情又很酷 2020-12-03 08:27

I have an RTF file that I want to display inside a web page after tags have been replaced with user input.

I would like to be able to display the RTF file without

相关标签:
7条回答
  • 2020-12-03 08:32

    You can't just output a file from within PHP code. You need to extract the data from it, then print the contents inline.

    The php function 'file_get_contents' may do what you need. The functions manual is here: http://us2.php.net/filegetcontents

    A sample usage is here:

    $contents = file_get_contents('yourfile.rtf');
    
    0 讨论(0)
  • 2020-12-03 08:33

    First: you've got your content-type wrong. for RTF it's text/rtf

    Second: you'll only be able to display in-line this type of content, which can be rendered by the web browser. RTF is not one of these. So you won't be able to display it in-line without converting it, or without some plug-in for the browser. Of course conversion might be on-the-fly.

    0 讨论(0)
  • 2020-12-03 08:36

    You needed an RTF to HTML converter written in PHP. I think this page contains your solution:

    http://www.websofia.com/2014/05/a-working-rtf-to-html-converter-in-php/

    0 讨论(0)
  • 2020-12-03 08:41

    This isn't exactly an answer to your question, but one thing you may want to do is remove the "filename=mark.rtf" from the header. I've had browsers treat something as a download if I include "filename" in the header, even if the "Content-Disposition" is "inline".

    0 讨论(0)
  • 2020-12-03 08:48

    You might want to check out https://github.com/tbluemel/rtf.js for client-side RTF rendering. It's still in its early stages but it renders even embedded graphics. Support for rendering embedded WMF artwork is still very very limited, though, and requires browser support for the tag.

    0 讨论(0)
  • 2020-12-03 08:51

    Web pages can only contain HTML. You would need a browser plugin like flash to display other file types. See Scribd for example.

    0 讨论(0)
提交回复
热议问题