[vox-tech] reading files into a web page

Micah Cowan vox-tech@lists.lugod.org
02 Feb 2002 21:43:56 -0800


On Sat, 2002-02-02 at 03:14, Mark K. Kim wrote:
> SSI can do that, like this:
> 
>    ...
>    <pre>
>       <!--#include virtual="/www/pcgm/bulletins" -->
>    </pre>
>    ...
> 
> I *think* that's the right syntax.  It's been eons since I've used SSI.
> Depending on the host, you may need to name your file with a special
> extension, like ".phtml" or something.  Of course, the server needs to
> support SSI.

Also, e.g., for Apache, the configuration file usually isn't set up with
SSI on by default - you'll need to manually indicate what extension (or
if you don't like that, what specific filenames) will need to be parsed
by the server.

  AddType text/html .shtml
  AddHandler server-parsed .shtml

> Better way would be with PHP:
> 
>    ...
>    <pre>
>       <?php
>          $fp = fopen("/www/pcgm/bulletins", "r");
>          fpassthru($fp);
>       ?>
>    </pre>
>    ...
> 
> You'll most likely need to name the file with a special extension like
> ".php3" or ".php".  Of course, the server needs to support PHP for this to
> work.

Personally, I prefer the SSI method - likely to be more efficient, I
think.  Regardless of what method you use, you should still realize that
escaping needs to be performed for things like < and & to make "legal"
HTML (even though both Mozilla and Netscape 4.7 appear to handle
unencoded cases fine) - also some older browsers may have trouble with >
and " as well.

You could do this with something like:

  perl -e 'undef $/; $_ = <STDIN>; for $a
(["&","&amp;"],["<","&lt;"],[">","&gt;"],['"'\"'"',"&quot;"]) {
s/$a->[0]/$a->[1]/g; } print' < ~/test.html

which you could execute with <!--#exec cmd="..."-->, but that'll need
another level of quote escaping (which is already not too great - see
the entry for &quot; above).  My suggestion would be to perform the
escaping without the server beforehand, so that you can then just
include it.

Micah