PHP5如何在创建$ _POST数组时处理POST数据? [英] how does PHP5 process POST data in creating $_POST array?

查看:69
本文介绍了PHP5如何在创建$ _POST数组时处理POST数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一个HTTP POST的wav文件保存到一个php页面。

当它放入一个POST变量时,PHP5会自动执行什么操作

$ _POST []超全局数组?我还没有找到关于

的任何信息....


我有一个脚本可以在PERL中做我想要的,但是我需要在

PHP中完成。

我认为PERL在做到这一点时做了一些魔术:

#### PERL CODE ####

读取(STDIN,$ buffer,$ ENV {''CONTENT_LENGTH''});


@pairs = split(/& /,$ buffer);


foreach $ pair(@pairs)

{

($ name,$ value)=拆分(/ = /,$ pair);


$ value = ~tr / + / /;

$ value = ~s /%([a -fA-F0-9] [a-fA-F0-9])/ pack(" C",hex($ 1))/ eg;


$ FORM {$ name } = $ value;

}

#### END PERL CODE ####


这是它分开的地方输出名称,值对,以及值,

相当于urldecode(),base64decode()(我是否正确?)


它看起来像PHP5自动执行base64decode()和

urldecode(),因为当我上厕所k在HTTP

会话的原始tcpdump中,我看到:


POST。< obscured> /save_wav.php.HTTP/1.0 ..

内容类型:.application / x-www-form-urlencoded ..

User-Agent:.BeVocal / 2.7.VoiceXML / 2.0.BVPlatform / 1.8.5 .rc1a ..

主持人:。< obscured> ..

内容长度:.147341 ..

通过:.1.1。 bvcapxy002:8080。(squid / 2.5.STABLE4)..

X-Forwarded-For:.10.0.121.215 ..

Cache-Control:.max-age = 0 ..

连接:.keep-alive ..

...

消息= RIFF%E4%C6%00%00WAVEfmt +% 10%00%00%00%01%00%01%00

(以下90K以上)


但是当我将数据视为$ _POST [''message''],我明白这一点:

RIFF?t\0\WAVEfmt?\ 0 \ 0 \ 0?\ 0?\ 0 @ ?\0\0 @?\\\?\ 0?\ 0 \ 0 \ 0data?s \ 0 \ 0?


+被翻译成 "并且%NN被翻译回正常

值。


所以,我的问题是,如果PHP5正在做base64decode和urldecode

自动,为什么我的数据仍然存在腐败?


以下是我试图保存它的方法:


/ / PHP代码


$ writepath =< some path> ;;

$ filename =" wavfile" ;;


$ wavdata = $ _ POST [" message"];

$ lpn = $ _ POST [" license_plate_number"];

$ callerid = $ _ POST [" callerid"];


file_put_contents(" $ writepath / $ filename-raw.wav"," $ wavdata");


file_put_contents(" $ writepath / $ filename-u.wav",urldecode($ wavdata));

//与原始文件完全相同


/ /结束PHP代码


这会将所有数据写入文件,我看到了wav标题,但

数据看起来不正确我将它与PERL的输出进行比较

脚本(我不确定是否在视觉上比较两个wav文件让我

任何东西)


还有其他办法我应该保存这个除了

file_put_contents()?


背景信息:

我有一个发送三件事的voicexml应用程序到我的php页面:

callerid(字符串)

license_plate_number(字符串)

消息(wav数据)


我没有问题访问:

$ _POST [" callerid"]

$ _POST [" license_plate_number"]


我的voiceXML应用程序将wav数据发送为audio / wav,并且enctype为

" application / x-www-form-urlencoded"

>
过去几天我一直在网上搜索,而且我已经卡住了b $ b


帮助,请?


Billy Becker

I need to save a wav file that is HTTP POSTed to a php page.
What does PHP5 do automatically to a POSTed variable when it puts it in
the $_POST[] superglobal array? I haven''t been able to find any info on
this....

I have a script that does what I want in PERL, but I need to do it in
PHP.
I think the PERL does something magic when it does this:
#### PERL CODE ####
read ( STDIN, $buffer, $ENV { ''CONTENT_LENGTH'' } );

@pairs = split ( /&/, $buffer );

foreach $pair ( @pairs )
{
($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM { $name } = $value;
}
#### END PERL CODE ####

This is where it separates out the name,value pairs, and for the value,
does the equivalent of urldecode(), base64decode() (am I correct?)

It looks like PHP5 is automatically doing base64decode() and
urldecode(), because when I look at the raw tcpdump of the HTTP
session, I see this:

POST.<obscured>/save_wav.php.HTTP/1.0..
Content-Type:.application/x-www-form-urlencoded..
User-Agent:.BeVocal/2.7.VoiceXML/2.0.BVPlatform/1.8.5.rc1a..
Host:.<obscured>..
Content-Length:.147341..
Via:.1.1.bvcapxy002:8080.(squid/2.5.STABLE4)..
X-Forwarded-For:.10.0.121.215..
Cache-Control:.max-age=0..
Connection:.keep-alive..
...
message=RIFF%E4%C6%00%00WAVEfmt+%10%00%00%00%01%00 %01%00
(90K more of this follows)

But when I look at the data as $_POST[''message''], I see this:
RIFFt\0\0WAVEfmt \0\0\0\0\0@\0\0@\0\0\0\0\0\0data?s\0\0?

the + was translated to " " and the %NN was translated back to normal
value.

So, my question is, if PHP5 is doing base64decode and urldecode
automatically, why is my data still coming across corrupt?

Here is how I''m trying to save it:

// PHP CODE

$writepath=<some path>;
$filename="wavfile";

$wavdata=$_POST["message"];
$lpn=$_POST["license_plate_number"];
$callerid=$_POST["callerid"];

file_put_contents("$writepath/$filename-raw.wav", "$wavdata");

file_put_contents("$writepath/$filename-u.wav", urldecode($wavdata));
// exactly same as raw file

// END PHP CODE

This writes all the data to a file, and I see the wav header, but the
data doesn''t look right when I compare it to the output from the PERL
script (i''m not sure if visually comparing two wav files get me
anything)

Is there another way I should be saving this besides
file_put_contents()?

Background info:
I have a voicexml app that sends three things to my php page:
callerid (string)
license_plate_number (string)
message (wav data)

I have no problem accessing:
$_POST["callerid"]
$_POST["license_plate_number"]

My voiceXML app sends the wav data as "audio/wav", and the enctype is
"application/x-www-form-urlencoded"

I''ve been searching all over the internet for the past few days and I''m
stuck.

help, please?

Billy Becker

推荐答案

_POST []超全球数组?我还没有找到关于

的任何信息....


我有一个脚本可以在PERL中做我想要的,但是我需要在

PHP中完成。

我认为PERL在做到这一点时做了一些魔术:

#### PERL CODE ####

read(STDIN,
_POST[] superglobal array? I haven''t been able to find any info on
this....

I have a script that does what I want in PERL, but I need to do it in
PHP.
I think the PERL does something magic when it does this:
#### PERL CODE ####
read ( STDIN,


buffer,


ENV {''CONTENT_LENGTH''});


@pairs = split(/& /,
ENV { ''CONTENT_LENGTH'' } );

@pairs = split ( /&/,


这篇关于PHP5如何在创建$ _POST数组时处理POST数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆