Save dynamic data to text file

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

    #1

    Save dynamic data to text file

    Can I save dynamically created data to a text file on the client's
    machine?

    Preferrably in a user named file through a save dialog box.

    Thanks

    Wayne

  • Erwin Moller

    #2
    Re: Save dynamic data to text file

    WayneBurrows wrote:
    Can I save dynamically created data to a text file on the client's
    machine?
    >
    Preferrably in a user named file through a save dialog box.
    Hi,

    You cannot directly save a file on the clients disk (luckily).
    But you can offer a download of the file.

    Just create a PHP script that sets the right headers, and produces the
    output.

    Have a look at the header function.
    You will find a few examples and also a few usercontributed notes:




    Regards,
    Erwin Moller
    >
    Thanks
    >
    Wayne
    >

    Comment

    • Michael S Bykov

      #3
      Re: Save dynamic data to text file

      On Nov 12, 11:37 am, WayneBurrows <wjburr...@gmai l.comwrote:
      Can I save dynamically created data to a text file on the client's
      machine?
      >
      Preferrably in a user named file through a save dialog box.
      >
      Thanks
      >
      Wayne
      <?php
      $string = "bla bla bla"; // file content
      $filename='some .txt';
      $mime_type = (PMA_USR_BROWSE R_AGENT == 'IE' ||
      PMA_USR_BROWSER _AGENT == 'OPERA')
      ? 'application/octetstream'
      : 'application/octet-stream';
      header('Content-Type: ' . $mime_type);
      if (PMA_USR_BROWSE R_AGENT == 'IE')
      {
      header('Content-Disposition: inline; filename="' . $filename .
      '"');
      header("Content-Transfer-Encoding: binary");
      header('Expires : 0');
      header('Cache-Control: must-revalidate, post-check=0, pre-
      check=0');
      header('Pragma: public');
      print $string;
      } else {
      header('Content-Disposition: attachment; filename="' .
      $filename . '.' . $ext . '"');
      header("Content-Transfer-Encoding: binary");
      header('Expires : 0');
      header('Pragma: no-cache');
      print $string;
      };

      ?>

      if you'll need any explanations - tell me.

      Comment

      Working...