Pergunta


I'm gonna strart with my use case, before i'll explane the problem i'm running in to.

I'm building a mobile application using the phonegap framework.
For this application i need to upload a file (a picture made with a camera).
On most platforms i can get this image back as a base64 encoded image.
I can send this back to the server, and it can decode it and save it. (and do some other funcy stuff as it's a QR code).

Now on symbian, i can't get back the base64 string, and i can only get the URI to the image. This isn't a problem, becouse i can use a xmlhttprequest to get the image data and encode it to base64 using javascript.

This methode works, but it gives me a problem.
The symbian browser appears to have a bug. It's a webkit based browser from 2005 (yes, it's that old, even on the newest s60 phones).
The bug is that it converts all characters that it doesn't know (not in an utf-8 table) to 2 bytes. If is remember correctly it was everything above 127.

I have tried to fix this bug using javascript, but it was a no go (btw, canvas and then getBinaries or something like that are not supported as canvas 2d is not supported by the browser).

So, i try to build a workaround in php to fix the bytes. This is what i have right now, though it's not working:

function getValidBin($bin, $offset = 0) {
    $binLength = sizeof($bin);
    for ($i = $offset; $i<=$binLength; $i++) {
        if ($i == $binLength) {
            return false;
        }
        if ($bin[$i] < 127) {

            $binT = $bin[$i] + $bin[$i+1];
            $bin2 = $bin;
            $bin2[$i] = $binT;
            $bin2[$i+1] = null;
            if (imagecreatefromstring($bin2) != false) {
                return $bin2;
            } else {
                $bin3 = getValidBin($bin2, $i);

                if ($bin3 != false) {
                    return $bin3;
                }
            }
        }
    }
}

This function is not working for some reason. I get the following warnings:

Warning: imagecreatefromstring() [function.imagecreatefromstring]: Data is not in a recognized format in /opt/content/erik/omnicol/HTML/WS/services/qrDecoder/QrDecoder.php on line 98

And i get:

Fatal error: Maximum function nesting level of '100' reached, aborting! in /opt/content/erik/omnicol/HTML/WS/services/qrDecoder/QrDecoder.php on line 87

This last one it quite easy to solve, i think, but i think i'de post it anyway.

Now, my question are:
Am i on the right track?
How do i solve the warning?

Thanks a lot in advance,
Erik

p.s. sorry if my english is bad. I'm not a native speaker, as i'm dutch.
p.s.2 The bug i was talking about is this one: http://markmail.org/message/iosbn3rbcgu5k6qt

EDIT: The solution for the max of 100 depth was harder then i thought it would be. So help on that would be great too.

Foi útil?

Solução 2

There was no solution for this problem.
I switched to the javascript side of the application to fix the bytes there.

Outras dicas

Why are you trying to create the image after each and every byte? And what is that recursion for? Can't you just run over the string and fix those double-bytes? Something like this:

function getValidBin($s) {
    $new_s = '';
    for ($i = 0; $i < strlen($bin) ; $i++)
    {
        $char = $s{$i};
        if (ord($char) > 127)
        {
            $char = chr(ord($char) + ord($s{$i}));
            $i++;
        }
        $new_s .= $char;
    }
}

You have to put in the already base64-decoded string.

I assumed that your line

$binT = $bin[$i] + $bin[$i+1];

was supposed to mean "if there is a character code > 127, add this and the next character code together and use it as a single character" and I assumed that this approach is really what you want (we can't know as we don't know your data).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top