闪到PHP的base64 EN code /德code [英] Flash to PHP base64 encode/decode

查看:191
本文介绍了闪到PHP的base64 EN code /德code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AS3为Base64 EN codeA JPG并将其传递给Javascript的。我试图使用AJAX到的base64 EN codeD字符串传递给PHP和让PHP去$ C C是$。 (我知道我可以把它发送回闪存和闪存可以去code,并将其发送到PHP,但我想省去了闪光的解码端)。

I'm using AS3 to base64 encode a JPG and pass it to Javascript. I'm attempting to use AJAX to pass that base64 encoded string to PHP and have PHP decode it. (I know I could send it back to Flash and Flash could decode it and send it to PHP, but I'm trying to eliminate the need for Flash on the decoding end).

看来,AS3的连接codeToBase64String()功能和PHP的 base64_de code()功能不使用相同的算法,因为PHP计算它为Base64 EN codeD对象,但似乎并没有将它输出正常。

It appears that AS3's encodeToBase64String() function and and PHP's base64_decode() function do not use the same algorithm, as PHP evaluates it as a base64 encoded object, but does not seem to output it properly.

有没有办法来纠正这个问题?

Is there a way to rectify this problem?

注:请没有关于不需要Javascript的职位。 JavaScript是在这里就不详述原因的必要步骤。

推荐答案

不知道什么可能会造成麻烦。我已经通过的base64 EN codeD数据从AS3到PHP了很多次,都没有遇到问题。

Not sure about what might be causing trouble. I've passed base64 encoded data to php from AS3 a lot of times and haven't run into problems.

我一般用<一个href="http://$c$c.google.com/p/as3crypto/source/browse/trunk/as3crypto/src/com/hurlant/util/Base64.as"相对=nofollow> Hurlant的的Base64 :: EN codeByteArray()在AS3方面,虽然。

I generally use Hurlant's Base64::encodeByteArray() in the AS3 side, though.

修改

像这样的东西可能有助于调试这个问题:

Something like this might help debugging this problem:

        var buffer:ByteArray = new ByteArray();
        for(var i:int = 0; i < 256; i++) {
            buffer[i] = i;
        }

        var str:String = Base64.encodeByteArray(buffer); // this is com.hurlant.util.Base64
        // post your data to your php (directly or through JS)

PHP测试code:

Php test code:

$str = $_REQUEST['str'];

$decoded = base64_decode($str);
file_put_contents("test.txt",$decoded);

在AS端,你发送一个字符串连接codeS每一个可能的字节值。 PHP的将取消code,并把它写入一个文件。现在,如果你用十六进制编辑器打开生成的文件,你会看到所有的数字从0到255(或为0x00 ... 0xFF的)。如果不是这种情况下,这可能会给上是什么导致了问题的线索。

In the AS side, you are sending a string that encodes every possible byte value. The php will decode it and write it to a file. Now, if you open the generated file with an hex editor, you should see all the numbers from 0 to 255 (or 0x00 ... 0xff). If this is not the case, this might give some hints on what's causing the problems.

PS:我会发布从AS到PHP直接只是为了简化故障排除。也许JS以某种方式搞乱你的数据(不太可能,因为的base64应该是安全的);但只是丢弃该问题的一个可能来源。

PS: I'd post from AS to PHP directly just to simplify troubleshooting. Maybe JS is messing with your data somehow (not likely since base64 should be safe); but just to discard a possible source of the problem.

这篇关于闪到PHP的base64 EN code /德code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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