How to save an HTML form's textarea to a file

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

    How to save an HTML form's textarea to a file

    I've seen a few ideas - figured I'd run it up the flagpole and see if
    anyone saluted

    Thanks in advance
  • Jerry Stuckle

    #2
    Re: How to save an HTML form's textarea to a file

    Petyr David wrote:
    I've seen a few ideas - figured I'd run it up the flagpole and see if
    anyone saluted
    >
    Thanks in advance
    >
    No, I only salute the American flag :-)

    Not being sure of your experience level, I'll give it a shot.

    You need to GET or POST the form to a url. In that url, use the
    appropriate $_GET or $_POST value to fetch the contents of the textarea.

    Then just open a file, write() the data and close() the file. Of
    course, you'll want to ensure you have a unique filename so you don't
    keep overwriting it. Or, if you just want to append to the file, ensure
    you lock the file before opening for append and unlock it after closing it.

    Or, did I not understand your question correctly? Or maybe not answer
    with sufficient detail?

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Tim Roberts

      #3
      Re: How to save an HTML form's textarea to a file

      Petyr David <phynkel@gmail. comwrote:
      >
      >I've seen a few ideas - figured I'd run it up the flagpole and see if
      >anyone saluted
      Since you are asking in a PHP newsgroup, I assume you are trying to do this
      in a PHP program, in which case it's essentially trivial. What have you
      tried?
      --
      Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      • Geoff Berrow

        #4
        Re: How to save an HTML form's textarea to a file

        Message-ID:
        <76a287f5-bfc6-4513-8b75-3f4bc9ef5f5d@y3 8g2000hsy.googl egroups.comfrom
        Petyr David contained the following:
        >I've seen a few ideas - figured I'd run it up the flagpole and see if
        >anyone saluted
        RTFM

        --
        Geoff Berrow 011000100110110 0010000000110
        001101101011011 001000110111101 100111001011
        100110001101101 111001011100111 010101101011
        The Slippery Hill Boys Tel: 07985 425932. American themed barn dances and bluegrass performances. Stoke on Trent, Newcastle under Lyme, Staffordshire, Cheshire and surrounding areas.

        Comment

        • Sjoerd

          #5
          Re: How to save an HTML form's textarea to a file

          On Aug 5, 4:23 am, Petyr David <phyn...@gmail. comwrote:
          I've seen a few ideas - figured I'd run it up the flagpole and see if
          anyone saluted
          You're basically saying this:
          "I have a problem, which I don't care to explain properly, but has
          something to do with saving forms to files. Solve it for me."

          Please read some of this:


          You could also find an answer to your question using Google (searching
          on "save form file php" or something like that).

          Comment

          • Krustov

            #6
            Re: How to save an HTML form's textarea to a file

            <comp.lang.ph p>
            <Petyr David>
            <Mon, 4 Aug 2008 19:23:15 -0700 (PDT)>
            <76a287f5-bfc6-4513-8b75-3f4bc9ef5f5d@y3 8g2000hsy.googl egroups.com>
            I've seen a few ideas - figured I'd run it up the flagpole and see if
            anyone saluted
            >

            <form action="form_su bmit.php" method="post">

            <textarea cols="55" rows="8" name="demo" class="burp"></textarea>

            input type="submit" name="Submit" value="PREVIEW GUESTBOOK ENTRY">

            </form>


            Then on the next page (i.e. form_submit.php ) .....

            $james=$_POST['demo'];

            $bond=strlen($j ames);
            if ($bond>777) {$james=substr( $james,0,777);}

            This will cut down and reduce text to characters - working on the
            assmption that some idiot will cut-n-paste a 50meg textfile .

            $james=str_repl ace("<","",$jam es);
            $james=str_repl ace(">","",$jam es);

            Again minor anti abuse stuff that will prevent nasty html code from
            being displayed and/or abused .

            $james=str_repl ace("&","",$jam es);
            $james=str_repl ace("#","",$jam es);

            Some more minor anti abuse stuff .

            $filename="walt her/ppk.php";
            $fp=fopen($file name,"w");
            fwrite ($fp,$james); fwrite ($fp,"\n");
            fclose($fp);


            (cant be bothered to type anything else in)

            But the above basic will get you started .

            Comment

            • The Hajj

              #7
              Re: How to save an HTML form's textarea to a file

              On Aug 5, 1:38 pm, Krustov <m...@privacy.n etwrote:
              >
              $james=str_repl ace("<","",$jam es);
              $james=str_repl ace(">","",$jam es);
              >
              Again minor anti abuse stuff that will prevent nasty html code from
              being displayed and/or abused .
              >
              $james=str_repl ace("&","",$jam es);
              $james=str_repl ace("#","",$jam es);
              >
              Would it be faster to use/safer to just user strip_tags ?


              Comment

              • Krustov

                #8
                Re: How to save an HTML form's textarea to a file

                <comp.lang.ph p>
                <The Hajj>
                <Tue, 5 Aug 2008 13:51:58 -0700 (PDT)>
                <752bdb7d-172d-4ebd-85cd-590bf22f09fb@l6 4g2000hse.googl egroups.com>
                $james=str_repl ace("<","",$jam es);
                $james=str_repl ace(">","",$jam es);

                Again minor anti abuse stuff that will prevent nasty html code from
                being displayed and/or abused .

                $james=str_repl ace("&","",$jam es);
                $james=str_repl ace("#","",$jam es);
                >
                Would it be faster to use/safer to just user strip_tags ?
                >
                Wouldnt it be good if people like yourself told newbies how to do stuff
                instead of just critisising other peoples posts .

                But no - that would kinda take away your smug self satisfying i know
                everything but i'm not about to tell others way of thinking wouldnt it .

                Comment

                • Michael Fesser

                  #9
                  Re: How to save an HTML form's textarea to a file

                  ..oO(Krustov)
                  >$james=str_rep lace("<","",$ja mes);
                  >$james=str_rep lace(">","",$ja mes);
                  >
                  >Again minor anti abuse stuff that will prevent nasty html code from
                  >being displayed and/or abused .
                  Wrong tool at the wrong place.
                  >$james=str_rep lace("&","",$ja mes);
                  >$james=str_rep lace("#","",$ja mes);
                  >
                  >Some more minor anti abuse stuff .
                  Same here. It will kill every legit use of these characters. You should
                  not manipulate the submitted data, but escape it where necessary. The
                  correct way to prevent cross-site scripting attacks (which are a _major_
                  threat BTW!) is to use htmlspecialchar s() on data output, not on input.
                  >$filename="wal ther/ppk.php";
                  >$fp=fopen($fil ename,"w");
                  >fwrite ($fp,$james); fwrite ($fp,"\n");
                  >fclose($fp);
                  file_put_conten ts() might be another option.

                  Micha

                  Comment

                  • Krustov

                    #10
                    Re: How to save an HTML form's textarea to a file

                    <comp.lang.ph p>
                    <Michael Fesser>
                    <Tue, 05 Aug 2008 23:20:52 +0200>
                    <6fgh94l3hnpuf3 r53e4klepscoqe5 2hund@4ax.com>
                    Wrong tool at the wrong place.
                    >
                    $james=str_repl ace("&","",$jam es);
                    $james=str_repl ace("#","",$jam es);

                    Some more minor anti abuse stuff .
                    >
                    Same here. It will kill every legit use of these characters. You should
                    not manipulate the submitted data, but escape it where necessary. The
                    correct way to prevent cross-site scripting attacks (which are a _major_
                    threat BTW!) is to use htmlspecialchar s() on data output, not on input.
                    >
                    Yet another user who only lives to critisise other people posts .

                    How long has it been since you last posted something useful and actually
                    helped a user .

                    Comment

                    • Michael Fesser

                      #11
                      Re: How to save an HTML form's textarea to a file

                      ..oO(Krustov)
                      ><comp.lang.php >
                      ><Michael Fesser>
                      ><Tue, 05 Aug 2008 23:20:52 +0200>
                      ><6fgh94l3hnpuf 3r53e4klepscoqe 52hund@4ax.com>
                      >
                      >Wrong tool at the wrong place.
                      >>
                      >$james=str_rep lace("&","",$ja mes);
                      >$james=str_rep lace("#","",$ja mes);
                      >
                      >Some more minor anti abuse stuff .
                      >>
                      >Same here. It will kill every legit use of these characters. You should
                      >not manipulate the submitted data, but escape it where necessary. The
                      >correct way to prevent cross-site scripting attacks (which are a _major_
                      >threat BTW!) is to use htmlspecialchar s() on data output, not on input.
                      >>
                      >
                      >Yet another user who only lives to critisise other people posts .
                      Wrong.
                      >How long has it been since you last posted something useful and actually
                      >helped a user .
                      4 minutes. Or 20 minutes, if you only take this thread into account.

                      Your code creates a new problem instead of solving one. I just fixed
                      your bug.

                      Micha

                      Comment

                      • Krustov

                        #12
                        Re: How to save an HTML form's textarea to a file

                        <comp.lang.ph p>
                        <Michael Fesser>
                        <Tue, 05 Aug 2008 23:40:21 +0200>
                        <30ih949hjcsm9u o57joqu7cionsun sdhvk@4ax.com>
                        $james=str_repl ace("&","",$jam es);
                        $james=str_repl ace("#","",$jam es);

                        Some more minor anti abuse stuff .
                        >
                        Same here. It will kill every legit use of these characters. You should
                        not manipulate the submitted data, but escape it where necessary. The
                        correct way to prevent cross-site scripting attacks (which are a _major_
                        threat BTW!) is to use htmlspecialchar s() on data output, not on input.
                        >
                        Yet another user who only lives to critisise other people posts .
                        >
                        Wrong.
                        >
                        Your wrong - for people like you tend not to reply to newbies asking
                        help - unless you can critisise another users post in doing so .

                        Why else do people like yourself subscribe to what is in effect a help
                        newsgroup where new users often ask for help .


                        Comment

                        • Michael Fesser

                          #13
                          Re: How to save an HTML form's textarea to a file

                          ..oO(Krustov)
                          ><comp.lang.php >
                          ><Michael Fesser>
                          ><Tue, 05 Aug 2008 23:40:21 +0200>
                          ><30ih949hjcsm9 uo57joqu7cionsu nsdhvk@4ax.com>
                          >
                          >$james=str_rep lace("&","",$ja mes);
                          >$james=str_rep lace("#","",$ja mes);
                          >
                          >Some more minor anti abuse stuff .
                          >>
                          >Same here. It will kill every legit use of these characters. You should
                          >not manipulate the submitted data, but escape it where necessary. The
                          >correct way to prevent cross-site scripting attacks (which are a _major_
                          >threat BTW!) is to use htmlspecialchar s() on data output, not on input.
                          >>
                          >
                          >Yet another user who only lives to critisise other people posts .
                          >>
                          >Wrong.
                          >>
                          >
                          >Your wrong - for people like you tend not to reply to newbies asking
                          >help - unless you can critisise another users post in doing so .
                          If I would just want to criticize you, I would have already mentioned
                          your stupid punctuation (a blank before the period is just wrong) and
                          your ridiculous introductory epos (newsgroup is obvious and the msgID
                          is already in the headers, there's no need to repeat them).

                          But I don't do that.
                          >Why else do people like yourself subscribe to what is in effect a help
                          >newsgroup where new users often ask for help .
                          Often enough I directly respond to an OP's question and post code
                          snippets if possible. And even in this particular case I indirectly
                          helped the OP by correcting a bug caused by your own code. Tell me: Of
                          how much help is a "help" that causes a new problem? The next time the
                          OP would have complained about not being able to post something about a
                          company called "Miller & Son". Good work, Mr. K.

                          But it doesn't really surprise me that you don't have the balls to
                          accept that your code was "suboptimal ".

                          Micha

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: How to save an HTML form's textarea to a file

                            Michael Fesser wrote:
                            .oO(Krustov)
                            >
                            ><comp.lang.php >
                            ><Michael Fesser>
                            ><Tue, 05 Aug 2008 23:40:21 +0200>
                            ><30ih949hjcsm9 uo57joqu7cionsu nsdhvk@4ax.com>
                            >>
                            >>>>>$james=str _replace("&","" ,$james);
                            >>>>>$james=str _replace("#","" ,$james);
                            >>>>>>
                            >>>>>Some more minor anti abuse stuff .
                            >>>>Same here. It will kill every legit use of these characters. You should
                            >>>>not manipulate the submitted data, but escape it where necessary. The
                            >>>>correct way to prevent cross-site scripting attacks (which are a _major_
                            >>>>threat BTW!) is to use htmlspecialchar s() on data output, not on input.
                            >>>>>
                            >>>Yet another user who only lives to critisise other people posts .
                            >>Wrong.
                            >>>
                            >Your wrong - for people like you tend not to reply to newbies asking
                            >help - unless you can critisise another users post in doing so .
                            >
                            If I would just want to criticize you, I would have already mentioned
                            your stupid punctuation (a blank before the period is just wrong) and
                            your ridiculous introductory epos (newsgroup is obvious and the msgID
                            is already in the headers, there's no need to repeat them).
                            >
                            But I don't do that.
                            >
                            >Why else do people like yourself subscribe to what is in effect a help
                            >newsgroup where new users often ask for help .
                            >
                            Often enough I directly respond to an OP's question and post code
                            snippets if possible. And even in this particular case I indirectly
                            helped the OP by correcting a bug caused by your own code. Tell me: Of
                            how much help is a "help" that causes a new problem? The next time the
                            OP would have complained about not being able to post something about a
                            company called "Miller & Son". Good work, Mr. K.
                            >
                            But it doesn't really surprise me that you don't have the balls to
                            accept that your code was "suboptimal ".
                            >
                            Micha
                            Micha,

                            Haven't you learned - he never accepts his code as "suboptimal ". It's
                            always perfect because it's what he uses. And anyone who tries to show
                            the weaknesses in his code or otherwise make it better gets attacked.

                            I do agree your way is much better - and safer.

                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • anthony.levensalor@gmail.com

                              #15
                              Re: How to save an HTML form's textarea to a file

                              On Aug 5, 3:10 am, Geoff Berrow <blthe...@ckdog .co.ukwrote:
                              >
                              RTFM
                              Mark this well, you won't see a more pedantic, asinine response to a
                              question again.

                              Comment

                              Working...