method="POST" changes '.' to '_'

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

    method="POST" changes '.' to '_'

    I am trying to use POST to transfer data to another page. When I do
    this, '.' characters get converted to"_". For example:

    #index.html:
    <form action="test.ph p" method="post">
    <input type="submit" name="filename. txt">
    </form>

    #test.php
    <html>
    <?php
    var_dump( $_POST );
    ?>
    </html>

    This displays:

    array(1) { ["filename_t xt"]= string(12) "Submit Query" }

    ie 'filename.txt' is changed to 'filename_txt'
    How can I stop this behaviour?

  • Andy Hassall

    #2
    Re: method=&quot;PO ST&quot; changes '.' to '_'

    On 6 Jul 2006 15:07:59 -0700, "Robert S" <robert.spam.me .senseless@gmai l.com>
    wrote:
    >I am trying to use POST to transfer data to another page. When I do
    >this, '.' characters get converted to"_". For example:
    >
    >#index.html:
    ><form action="test.ph p" method="post">
    ><input type="submit" name="filename. txt">
    ></form>
    >
    >#test.php
    ><html>
    ><?php
    >var_dump( $_POST );
    >?>
    ></html>
    >
    >This displays:
    >
    >array(1) { ["filename_t xt"]= string(12) "Submit Query" }
    >
    >ie 'filename.txt' is changed to 'filename_txt'
    >How can I stop this behaviour?
    You'd have to patch PHP.

    See main/php_variables.c , php_register_va riable_ex
    (line 92 in PHP 5.1.4):

    /* ensure that we don't have spaces or dots in the variable name (not binary
    safe) */
    for (p = var; *p; p++) {
    if (*p == ' ' || *p == '.') {
    *p='_';
    } else if (*p == '[') {
    is_array = 1;
    ip = p;
    *p = 0;
    break;
    }
    }
    var_len = p - var;

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Robert S

      #3
      Re: method=&quot;PO ST&quot; changes '.' to '_'

      I am trying to use POST to transfer data to another page. When I do
      this, '.' characters get converted to"_". For example:
      You'd have to patch PHP.
      >
      Thanks for the speedy answer.

      Is there another way? I'm using debian on a work PC and am extremely
      reluctant to do any patching.

      Comment

      • Alvaro G. Vicario

        #4
        Re: method=&quot;PO ST&quot; changes '.' to '_'

        *** Robert S escribió/wrote (6 Jul 2006 15:34:38 -0700):
        Is there another way? I'm using debian on a work PC and am extremely
        reluctant to do any patching.
        Why don't do simply perform some sort of encoding and decoding, like
        bin2hex() or base64_encode() or even a custom one?

        --
        -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        ++ Mi sitio sobre programación web: http://bits.demogracia.com
        +- Mi web de humor con rayos UVA: http://www.demogracia.com
        --

        Comment

        • Andy Hassall

          #5
          Re: method=&quot;PO ST&quot; changes '.' to '_'

          On 6 Jul 2006 15:34:38 -0700, "Robert S" <robert.spam.me .senseless@gmai l.com>
          wrote:
          >I am trying to use POST to transfer data to another page. When I do
          >this, '.' characters get converted to"_". For example:
          >
          > You'd have to patch PHP.
          >>
          >
          >Thanks for the speedy answer.
          >
          >Is there another way? I'm using debian on a work PC and am extremely
          >reluctant to do any patching.
          If you're brave, then there's $HTTP_RAW_POST_ DATA, but since you'll then have
          to do your own POST-data decoding then beware of getting it wrong.

          Just going back to your original post:
          <form action="test.ph p" method="post">
          <input type="submit" name="filename. txt">
          </form>
          Are you committed to this layout? "filename.t xt" can exist fine as a value,
          it's just as a name it's a problem. Can you not send the filename over as a
          value in an input type=hidden field, for example?

          --
          Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
          http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

          Comment

          • flamer die.spam@hotmail.com

            #6
            Re: method=&quot;PO ST&quot; changes '.' to '_'

            umm why dont you just (on the test.php page) do a str replace and
            change the '_' back to a '.' ??

            flamer.

            Robert S wrote:
            I am trying to use POST to transfer data to another page. When I do
            this, '.' characters get converted to"_". For example:
            >
            #index.html:
            <form action="test.ph p" method="post">
            <input type="submit" name="filename. txt">
            </form>
            >
            #test.php
            <html>
            <?php
            var_dump( $_POST );
            ?>
            </html>
            >
            This displays:
            >
            array(1) { ["filename_t xt"]= string(12) "Submit Query" }
            >
            ie 'filename.txt' is changed to 'filename_txt'
            How can I stop this behaviour?

            Comment

            • Robert S

              #7
              Re: method=&quot;PO ST&quot; changes '.' to '_'

              >
              Why don't do simply perform some sort of encoding and decoding, like
              bin2hex() or base64_encode() or even a custom one?
              >
              Thanks. That looks like the best idea. Fortunately the program that
              creates the files seems to give the files "safe" filenames, except for
              the '.' with the extension. I might just trim off the extension and
              add it at the other end. bin2hex also looks promising.

              Comment

              • Jerry Stuckle

                #8
                Re: method=&quot;PO ST&quot; changes '.' to '_'

                Geoff wrote:
                On 6 Jul 2006 16:03:14 -0700, flamer die.spam@hotmai l.com wrote...
                >
                >>umm why dont you just (on the test.php page) do a str replace and
                >>change the '_' back to a '.' ??
                >>
                >>flamer.
                >
                >
                Thought about that too, but could have a problem with
                >
                <input type="submit" name="file_name .txt">
                >
                becoming "file.name.txt" , if other form fields are using that logic.
                >
                Saw someone else (Andy?) mention the "name" being the problem and not the value.
                Instead of messing around with the ".txt", name it "filename" and append a
                ".txt" later if it's that crucial to the program.
                >
                >
                Geoff
                >
                Geoff,

                Remember - the name attribute is just something for you to identify the
                data when it's passed. It does not have to be an actual filename - it
                could be "xyz" for that matter. But it HAS to be changed, because '.'
                is not a valid character in a PHP variable.

                Whatever you have here is the identifier in the $_POST or $_GET array,
                i.e. $_POST['xyz'].

                The value in the field is where you want "filename.t xt", and that should
                not be changed.


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

                Comment

                • Toby Inkster

                  #9
                  Re: method=&quot;PO ST&quot; changes '.' to '_'

                  Robert S wrote:
                  <form action="test.ph p" method="post">
                  <input type="submit" name="filename. txt">
                  </form>
                  Why are you even passing the filename in a button's name?

                  Why not:

                  <form action=test.php method=post>
                  <div>
                  <input type=hidden name=myfile value="filename .txt">
                  <input type=submit>
                  </div>
                  </form>

                  ??

                  --
                  Toby A Inkster BSc (Hons) ARCS
                  Contact Me ~ http://tobyinkster.co.uk/contact

                  Comment

                  • Robert S

                    #10
                    Re: method=&quot;PO ST&quot; changes '.' to '_'

                    Why are you even passing the filename in a button's name?
                    >
                    Why not:
                    >
                    <form action=test.php method=post>
                    <div>
                    <input type=hidden name=myfile value="filename .txt">
                    <input type=submit>
                    </div>
                    </form>
                    The page is a fax client that allows large numbers of files to be faxed
                    off to multiple recipients. I have a whole lot of buttons and text
                    inputs that refer to different files. The receiving page loops through
                    $POST and identifies the file that the button refers to. All text
                    inputs and checkboxes etc need to be sent to the receiving page, so I
                    can't use multiple <formelements . The example I gave was just an
                    illustrative example - its not from my code. As far as I can see this
                    seems to be the only way of doing it. The files are .PDF files created
                    by cups-pdf - so they are FULL of underscores. If I use an <a href>
                    tag, the POST variables don't get sent to the receiving page.

                    bin2hex looks like the way to go.

                    Comment

                    • jussist@gmail.com

                      #11
                      Re: method=&quot;PO ST&quot; changes '.' to '_'


                      Robert S wrote:
                      Why are you even passing the filename in a button's name?

                      Why not:

                      <form action=test.php method=post>
                      <div>
                      <input type=hidden name=myfile value="filename .txt">
                      <input type=submit>
                      </div>
                      </form>
                      >
                      The page is a fax client that allows large numbers of files to be faxed
                      off to multiple recipients. I have a whole lot of buttons and text
                      inputs that refer to different files. The receiving page loops through
                      $POST and identifies the file that the button refers to. All text
                      inputs and checkboxes etc need to be sent to the receiving page, so I
                      can't use multiple <formelements . The example I gave was just an
                      illustrative example - its not from my code. As far as I can see this
                      seems to be the only way of doing it. The files are .PDF files created
                      by cups-pdf - so they are FULL of underscores. If I use an <a href>
                      tag, the POST variables don't get sent to the receiving page.
                      >
                      bin2hex looks like the way to go.
                      In my mind if you cannot avoid having those periods in the form-fields,
                      you have a design problem in your code. For example:

                      <input type="hidden" name="filename1 " value="filename 1.txt">
                      <input type="submit" name="SubmitStu ff1">

                      <input type="hidden" name="filename2 " value="filename 2.txt">
                      <input type="submit" name="SubmitStu ff2">

                      With this kind of stuff on the target page you get the filename by:

                      if( isset($_POST["SubmitStuf f1"])) {
                      $MyFilename = $_POST["filename1"];
                      }

                      or

                      for($i=0;$i<100 ;$i++) {
                      if(isset($_POST["SubmitStuff".$ i)) {
                      $MyFilename = $_POST["filename". $i];
                      }
                      }

                      and so forth. You never really need a period in the field name, unless
                      the form is produced by some other software, generator, or some
                      framework, but these are other issues then.

                      Comment

                      • Robin

                        #12
                        Re: method=&quot;PO ST&quot; changes '.' to '_'

                        Robert S wrote:
                        >>Why are you even passing the filename in a button's name?
                        >>
                        >>Why not:
                        >>
                        >> <form action=test.php method=post>
                        >> <div>
                        >> <input type=hidden name=myfile value="filename .txt">
                        >> <input type=submit>
                        >> </div>
                        >> </form>
                        >
                        >
                        The page is a fax client that allows large numbers of files to be faxed
                        off to multiple recipients. I have a whole lot of buttons and text
                        inputs that refer to different files. The receiving page loops through
                        $POST and identifies the file that the button refers to. All text
                        inputs and checkboxes etc need to be sent to the receiving page, so I
                        can't use multiple <formelements . The example I gave was just an
                        illustrative example - its not from my code. As far as I can see this
                        seems to be the only way of doing it. The files are .PDF files created
                        by cups-pdf - so they are FULL of underscores. If I use an <a href>
                        tag, the POST variables don't get sent to the receiving page.
                        >
                        bin2hex looks like the way to go.
                        >
                        If you don't mind assuming that javascript is on then:

                        one of these:
                        <input type='hidden' name='myfile' value='' />

                        and many of (assuming form's name is 'myform'):
                        <input type='submit'
                        onclick='docume nt.myform.myfil e.value="filena me.txt"' />

                        -------------------------------------------------
                        Alternatively, assuming the buttons have the filename as their text,
                        just have many:

                        <input type='submit' name='myfile' value='filename 1.txt' />
                        <input type='submit' name='myfile' value='filename 2.txt' />
                        <input type='submit' name='myfile' value='filename 2.txt' />
                        ....

                        then $_POST['myfile'] should be the value field of the clicked submit
                        button.

                        Comment

                        • Robert S

                          #13
                          Re: method=&quot;PO ST&quot; changes '.' to '_'

                          Both of these suggestions look good. I'm using javascript already and
                          that looks like the most elegant method.

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: method=&quot;PO ST&quot; changes '.' to '_'

                            Robert S wrote:
                            >>Why are you even passing the filename in a button's name?
                            >>
                            >>Why not:
                            >>
                            >> <form action=test.php method=post>
                            >> <div>
                            >> <input type=hidden name=myfile value="filename .txt">
                            >> <input type=submit>
                            >> </div>
                            >> </form>
                            >
                            >
                            The page is a fax client that allows large numbers of files to be faxed
                            off to multiple recipients. I have a whole lot of buttons and text
                            inputs that refer to different files. The receiving page loops through
                            $POST and identifies the file that the button refers to. All text
                            inputs and checkboxes etc need to be sent to the receiving page, so I
                            can't use multiple <formelements . The example I gave was just an
                            illustrative example - its not from my code. As far as I can see this
                            seems to be the only way of doing it. The files are .PDF files created
                            by cups-pdf - so they are FULL of underscores. If I use an <a href>
                            tag, the POST variables don't get sent to the receiving page.
                            >
                            bin2hex looks like the way to go.
                            >
                            OK, no problem. Just:

                            <form action=test.php method=post>
                            <input type=hidden name="filename[0]" value="filename .txt">
                            <input type=submit name="Submit[0]">
                            <input type=hidden name="filename[1]" value="filename .pdf">
                            <input type=submit name="Submit[1]">
                            <input type=hidden name="filename[2]" value="filename .doc">
                            <input type=submit name="Submit[2]">
                            <input type=hidden name="filename[3]" value="filename .html">
                            <input type=submit name="Submit[3]">
                            </form>

                            File names are in $_POST['filename[0]'], $_POST['filename[1]'], etc.
                            The button which was pressed will be in $_POST['Submit[x]'].

                            Simply loop through the Submit array to find which one was pressed with
                            isset(), and pick the appropriate file from the filename array.

                            Expandable, easily programmed and requires no JS.


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

                            Comment

                            • Robert S

                              #15
                              Re: method=&quot;PO ST&quot; changes '.' to '_'

                              >
                              OK, no problem. Just:
                              >
                              <form action=test.php method=post>
                              <input type=hidden name="filename[0]" value="filename .txt">
                              <input type=submit name="Submit[0]">
                              <input type=hidden name="filename[1]" value="filename .pdf">
                              <input type=submit name="Submit[1]">
                              <input type=hidden name="filename[2]" value="filename .doc">
                              <input type=submit name="Submit[2]">
                              <input type=hidden name="filename[3]" value="filename .html">
                              <input type=submit name="Submit[3]">
                              </form>
                              >
                              Simply loop through the Submit array to find which one was pressed with
                              isset(), and pick the appropriate file from the filename array.
                              >
                              I've gone for this approach. Works a treat. Many thanks for the help
                              folks.

                              Comment

                              Working...