Menu

send Rtf file directly to browser ?

PhpRtf
webcarle
2012-07-18
2015-06-04
  • webcarle

    webcarle - 2012-07-18

    Is there a way to send Rtf file directly to browser  without saving to file before ?

     
  • Anonymous

    Anonymous - 2012-07-24

    well I tried this with one of the examples:
    just add this headers at the begining of the file, just after the includes if you want, but before any output

    <?php
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=file.rtf");
    /*
    populating the file...
    */
    $rtf->save('php://output');
    ?>
    

    so basically you are telling the server to output directly to the browser instead of a file stream, and with the headers you are telling the browser the type and how to handle the file.

     
    • Starikov Sergey

      Starikov Sergey - 2015-06-04

      To my experience it is not completely correct.
      In my case such code produced invalid rtf file.
      The right one is:

       header("Pragma: public");
       header('Content-disposition: attachment; filename='.$rtf_filename);
       header('Content-type: application/rtf');
       header('Content-Transfer-Encoding: binary');
       ob_clean();
       flush();
       $rtf->save('php://output');
      
       
  • webcarle

    webcarle - 2012-07-24

    Thank you for your answer.
    I've already found the solution by reading the source files
    just write this:

    $rtf->sendRtf($filename.'.rtf'); // (filename is just de name without path…

    this will send the rtf directly to the browser ready to save under the name $filename.rtf  (and nothing saved on server).

     

Log in to post a comment.