SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Mar 2001
    Location
    Highlands Ranch, Colorado
    Posts
    614
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form to text file

    I am wondering how to set this up.

    The visitors of my site shall be able to put some data into a form. When processing this form I want to take this data and save it into a text file in a specific format - but directly to the users hard drive. The user shall get this normal promp to save it to the disk or run it from that location - my intention is that the user can save this file to his hard drive.

    I already have a form that usually emails me the data - but now I like to process it right away and save it to the users hard drive.

    What might be the best attempt to do this?

    Thanks!

    C.
    The-USA dot net - PR4 Web Directory

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what languages do you have access to? What server/platform?

    There are two parts to accomplish what you need.

    1. The user submits the data to a script, you have this already.

    2. The script needs to be named .txt You can set up an .htaccess file to parse .txt files as php (assuming you're using apache and php)

    Relatively simple to do, again assuming you're using php and apache.

    If you're using Perl you could do it the same way, you'd simply have to set up the txt file as a perl script.


    Also usually browser don't prompt for downloads when dealing with text files, they usually just display them. I'm not sure how you'd get it to prompt the user for a download.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Guru
    Join Date
    Mar 2001
    Location
    Highlands Ranch, Colorado
    Posts
    614
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Aspen,

    I have access to php and Perl on my server - it is a Red Hat 7.x Linux server.

    The current form script I use just triggers an email and sends the data to me. Do you think I could just use the same form and script and make the adjustements that you mention?

    What exactly do I need to do with the .htaccess file - I never 'played' with that so far?!

    Hm, the browser does not prompt to download a text file? Actually - the txt file will need to be printed out by the user as the last step anyway (I wanted to save it for him as a convenient way to come back and use the file again without having the form to fill out - I could avoid saving it and print it directly. How can I set that up so that it only prints the content of the form in the right formatting? I need to avoid that the URL information, ect. will be printed out, too.

    Thanks!

    C.
    The-USA dot net - PR4 Web Directory

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you print from a browser it'll tag on the url etc. Thats a browser setting, can't do much about that.

    But here is what you need to do.

    Create a directory, lets say you call it "output"

    so the path to it is

    http://www.domain.com/output/

    next what you need to do in output is put a file called .htaccess

    .htaccess is a specially named text file that lets you manipulate server settings.

    put the following line in it:

    AddHandler application/x-httpd-php .txt

    This will tell the server to parse .txt files for php

    Then I'm assuming you know php, but if not, to access a variable with php all you need to know is the name of the input used in your form.

    So if you have

    <input type = "text" name = "first_name">

    to access that value once its submitted all you need to do is uyse $first_name ($ identifies a variable)

    So make your form submit to the .txt page. Then in your .txt page you need to just do a few lines like this

    PHP Code:
    <?
    echo $name;
    echo 
    "<br>";
    echo 
    $comments;
    ?>
    And that's it. It'd then be up to the user to save it or print it.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •