Save Image as Blob in Db

811 views Asked by At

In my application the user needs to register himself. In the proces he needs to take a picture. I would like to save the picture in the database. It's an Flex mobile project and I use php. Here is what I've got so far:

In as:

   var bitmapdata:BitmapData=this.data as BitmapData;
   var encoder:JPEGEncoder=new JPEGEncoder(85);
   var stream:ByteArray=encoder.encode(bitmapdata);
   var b64:Base64Encoder=new Base64Encoder();
   b64.encodeBytes(stream);

   var obj:Object=new Object();
   obj.test="test";
   obj.bytes=b64;

   netCon=new NetConnection();
   netCon.connect(".../gateway.php");
   var resp:Responder=new Responder(resultHandler, faultHandler);
   netCon.call("gotcha.registerUserPic",resp,stream);

In php:

function registerUserPic($paramObj){
        $test=addslashes($paramObj['test']);
        $data=addslashes($paramObj['bytes']);
        $decodeddata=base64_decode($data);
        $sql="INSERT INTO `dbName`.`upload` (`id`,`content`) VALUES (NULL, '$decodeddata');";
        $result = mysql_query($sql);
        return $result;
        }

But he won't save the byteArray in the BLOB Field.

When I trace the b64 = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEP.. ."

I have no idea how to solve this.

0

There are 0 answers