+ Reply to Thread
Results 1 to 3 of 3

Thread: String to text file

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    String to text file

    I am looking for a script that will allow me to turn a string to a text file for the user to download without having to save the file to my server.

    If this is possible can anyone help me with a sample. I have looked all over google but it just shows me how to save to a text file on the server.

    Thanks for any help

  2. #2
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Re: String to text file

    I managed to figure this one out on my own. This is the code im currently using. If there is a better way I would appreciate the advice.

    Code:
    header('Cache-Control: private');
    header('Pragma: private');
    header("Content-Disposition: attachment; filename=\"file.txt\"");
    header("Content-Type: application/octet-stream;");
    echo $_POST['content'];

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: String to text file

    That's basically the best way. With the Content-Disposition header, you should be able to set the proper MIME type for the content. If the string is text, set the Content-type to "text/plain".
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Can Javascript read a file to a string?
    By tscrap in forum Programming Help
    Replies: 9
    Last Post: 05-21-2010, 02:02 AM
  2. Can javascript read a file to a string or array?
    By tscrap in forum Free Hosting
    Replies: 4
    Last Post: 05-20-2010, 11:33 AM
  3. cPanel : problem with a text file
    By fomalhaut in forum Programming Help
    Replies: 5
    Last Post: 11-23-2009, 01:46 PM
  4. call a template and a text file together
    By bnrj_sjy in forum Programming Help
    Replies: 4
    Last Post: 09-16-2009, 12:54 PM
  5. any help with: Send data to a Text File
    By anilson1 in forum Programming Help
    Replies: 2
    Last Post: 10-30-2008, 12:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers