f



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.php" method="post">
<input type="submit" name="filename.txt">
</form>

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

This displays:

array(1) { ["filename_txt"]=>  string(12) "Submit Query" }

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

0
7/6/2006 10:07:59 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

15 Replies
915 Views

Similar Articles

[PageSpeed] 31

On 6 Jul 2006 15:07:59 -0700, "Robert S" <robert.spam.me.senseless@gmail.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.php" method="post">
><input type="submit" name="filename.txt">
></form>
>
>#test.php
><html>
><?php
>var_dump( $_POST );
>?>
></html>
>
>This displays:
>
>array(1) { ["filename_txt"]=>  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_variable_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.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
0
andy171 (2271)
7/6/2006 10:25:19 PM
> >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.

0
7/6/2006 10:34:38 PM
*** 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
--
0
7/6/2006 10:47:52 PM
On 6 Jul 2006 15:34:38 -0700, "Robert S" <robert.spam.me.senseless@gmail.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.php" method="post">
> <input type="submit" name="filename.txt">
> </form>

 Are you committed to this layout? "filename.txt" 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.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
0
andy171 (2271)
7/6/2006 10:49:13 PM
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.php" method="post">
> <input type="submit" name="filename.txt">
> </form>
>
> #test.php
> <html>
> <?php
> var_dump( $_POST );
> ?>
> </html>
>
> This displays:
>
> array(1) { ["filename_txt"]=>  string(12) "Submit Query" }
>
> ie 'filename.txt' is changed to 'filename_txt'
> How can I stop this behaviour?

0
die.spam (165)
7/6/2006 11:03:14 PM
>
> 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.

0
7/6/2006 11:24:19 PM
On 6 Jul 2006 16:03:14 -0700, flamer die.spam@hotmail.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

-- 
Newsguy Unlimited $19.95 monthly
http://newsguy.com/overview.htm 




>
>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.php" method="post">
>> <input type="submit" name="filename.txt">
>> </form>
>>
>> #test.php
>> <html>
>> <?php
>> var_dump( $_POST );
>> ?>
>> </html>
>>
>> This displays:
>>
>> array(1) { ["filename_txt"]=>  string(12) "Submit Query" }
>>
>> ie 'filename.txt' is changed to 'filename_txt'
>> How can I stop this behaviour?
>

0
geoff3994 (2)
7/7/2006 1:07:46 AM
Geoff wrote:
> On 6 Jul 2006 16:03:14 -0700, flamer die.spam@hotmail.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.txt", and that should 
not be changed.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
7/7/2006 1:44:55 AM
Robert S wrote:

> <form action="test.php" 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

0
7/7/2006 6:52:33 AM
> 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 <form> elements.  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.

0
7/7/2006 7:26:31 AM
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 <form> elements.  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="filename1.txt">
<input type="submit" name="SubmitStuff1">

<input type="hidden" name="filename2" value="filename2.txt">
<input type="submit" name="SubmitStuff2">

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

if( isset($_POST["SubmitStuff1"])) {
  $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.

0
jussist (23)
7/7/2006 8:53:14 AM
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 <form> elements.  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='document.myform.myfile.value="filename.txt"' />

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

<input type='submit' name='myfile' value='filename1.txt' />
<input type='submit' name='myfile' value='filename2.txt' />
<input type='submit' name='myfile' value='filename2.txt' />
....

then $_POST['myfile'] should be the value field of the clicked submit 
button.
0
anon10 (52)
7/7/2006 9:23:48 AM
Both of these suggestions look good.  I'm using javascript already and
that looks like the most elegant method.

0
7/7/2006 10:19:59 AM
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 <form> elements.  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@attglobal.net
==================
0
jstucklex (14659)
7/7/2006 11:36:11 AM
>
> 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.

0
7/7/2006 1:22:35 PM
Reply: