Problem with converting HTML to Word/Excel/Etc.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

    Problem with converting HTML to Word/Excel/Etc.

    Based on the information I read in www.php.net on the header command I wrote
    a dummy test script to try to convert the contents of $stuff to MS Word
    downloadable format:



    Code:


    $stuff = '<html><head><t itle>stuff</title></head><body><b>H ello</b>
    World</body></html>';

    header("Expires : Mon, 26 Jul 1997 05:00:00 GMT"); // Date in
    the past
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always
    modified
    header("Cache-Control: no-store, no-cache, must-revalidate"); //
    HTTP/1.1
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache"); //
    HTTP/1.0

    header("Content-type: application/msword; filename=stuff. doc");
    //header("Content-Disposition: attachment; filename=stuff. doc");
    echo $stuff;


    However, upon attempting to run this script I ran into the following error
    in IE:

    Internet Explorer could not open this script: test.php (note: I am trying to
    change it to be "stuff.doc" ). Nothing ever showed up.

    test.php (the code you see) is in a Linux environment in a folder protected
    by .htaccess.

    In NS 7.0 it produces no errors but it tries to save the downloaded file as
    "test.php" and not "stuff.doc" .

    I am unsure how to do this in PHP although I can do it in TCL and have done
    it that way before, that, however, is not an option here.

    Please help, I'm stuck at the very beginning of attempting customized simple
    reporting.

    Thanx
    Phil


  • Janwillem Borleffs

    #2
    Re: Problem with converting HTML to Word/Excel/Etc.


    "Phil Powell" <soazine@erols. com> schreef in bericht
    news:%Ckkb.8957 7$0Z5.43633@lak eread03...[color=blue]
    >
    > I am unsure how to do this in PHP although I can do it in TCL and have[/color]
    done[color=blue]
    > it that way before, that, however, is not an option here.
    >
    > Please help, I'm stuck at the very beginning of attempting customized[/color]
    simple[color=blue]
    > reporting.
    >[/color]

    The following should be enough to download any word document:

    <?
    // Code which retrieves the word document as $stuff
    // .....
    header("Content-Disposition: attachment; filename=stuff" .time().".doc") ;
    echo $stuff

    ?>

    This way, the browser will always download a new version because the
    filename is unique with the appended return value of the time() function.

    Using a content-type header is not necessary, unless the .doc extension is
    already associated on the server.


    JW



    Comment

    • Phil Powell

      #3
      Re: Problem with converting HTML to Word/Excel/Etc.

      Thanx, however, I just found out that business requirements indicate that it
      is embedded, so I can't use "attachment "; I have to use "inline" instead.
      And it could be .doc, .xls, .pdf, .rtf or .html now. More work to do. :(
      but Thanx though!

      Phil

      "Janwillem Borleffs" <jw@jwscripts.c om> wrote in message
      news:3f92a32a$0 $2725$1b62eedf@ news.euronet.nl ...[color=blue]
      >
      > "Phil Powell" <soazine@erols. com> schreef in bericht
      > news:%Ckkb.8957 7$0Z5.43633@lak eread03...[color=green]
      > >
      > > I am unsure how to do this in PHP although I can do it in TCL and have[/color]
      > done[color=green]
      > > it that way before, that, however, is not an option here.
      > >
      > > Please help, I'm stuck at the very beginning of attempting customized[/color]
      > simple[color=green]
      > > reporting.
      > >[/color]
      >
      > The following should be enough to download any word document:
      >
      > <?
      > // Code which retrieves the word document as $stuff
      > // .....
      > header("Content-Disposition: attachment; filename=stuff" .time().".doc") ;
      > echo $stuff
      >
      > ?>
      >
      > This way, the browser will always download a new version because the
      > filename is unique with the appended return value of the time() function.
      >
      > Using a content-type header is not necessary, unless the .doc extension is
      > already associated on the server.
      >
      >
      > JW
      >
      >
      >[/color]


      Comment

      Working...