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).
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?
Note: Please no posts about not needing Javascript. Javascript is a necessary step for reasons not detailed here.
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.
I generally use Hurlant’s Base64::encodeByteArray() in the AS3 side, though.
Edit
Something like this might help debugging this problem:
Php test code:
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: 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.