I have an image in the database stored in blob format, I have to use base64_encode in php before returning the ajax request and this is leaving the process kind of slow on the server side. It is possible to do or have some native function in javascript or jQuery to do this same base64_encode side of the client in javascript?
current scenario: javascript
fun.ajaxFoto = custom.ajaxAsync(p,'getFoto','../view/rh/vFuncionarioDetalhes.php');
fun.ajaxFoto.done(function(json){
$("#fun_foto").empty();
var img = $('<img>').attr('src',"data:image/jpg;base64," + json.fun_foto);
});
go to the file vFuncionarioDetalhes.php
function getFoto(){
global $colFuncionario;
$obj = (object) $_REQUEST['obj'];
$json = $colFuncionario->getFoto($obj);
// QUERIA MUDAR ESSA LINHA ABAIXO E ENTREGAR DIRETO O $json->fun_foto
$json->fun_foto = base64_encode( $json->fun_foto );
echo json_encode( $json );
}
Controller
public function getFoto($obj){
global $c;
$objResult = new stdClass();
$c->conCordilheira();
$mQuery = "select * from tab_cordilheira_ferias_gozo where fun_id =".$obj->fun_id;
$query = "SELECT fd.foto as fun_foto FROM fundocumento fd where fd.cd_empresa=2011 and fd.cd_funcionario=".$obj->fun_id;
$result = mssql_query($query);
$obj02 = mssql_fetch_object($result);
//$result = odbc_exec($conn, $query);
$c->conectarNovamente(@$_SESSION["usuario"],@$_SESSION["senha"]);
$mResult = mysql_query($mQuery);
$objM = mysql_fetch_object($mResult);
//$obj02 = odbc_fetch_object($result);
$objResult->fun_dt_ferias = $objM->fun_mes_gozo;
$objResult->fun_foto = $obj02->fun_foto;
return $objResult;
}
I'll leave the string in blob format for testing
$json->fun_foto="0xFFD8FFE1348345786966000049492A000800000011000E01020020000000DA0000000F01020005000000FA0000001001020009000000000100001A010500010000000A0100001B0105000100000012010000280103000100000002008A8732010200140000001A01000013020300010000000200838169870400010000004A01000001A40300010000000000898902A40300010000000000837F03A40300010000000000857F06A40300010000000000877E08A403000100000000007D7409A40300010000000000887F0AA403000100000000008179A5C407001C0000002E010000501500002020202020202020202020202020202020202020202020202020202020202000534F4E5900004453432D57333230000048000000010000004800000001000000323031333A30333A30342031363A30353A3234005072696E74494D00303330300000020002000100000001010100000016009A82050001000000580200009D820500010000006002000022880300010000000200FEFB27880300010000004006FFFB00900700040000003032323103900200140000006802000004900200140000007C02000001910700040000000102030002910500010000009002000004920A0001000000980200000592050001000000A002000007920300010000000500FFFF08920300010000000000FFFF09920300010000001000FFFE0A92050001000000A80200007C920700A0120000B002000000A00700040000003031303001A00300010000000100FFFF02A0040001000000B00A000003A0040001000000400E000000A307000100000003FEFEFE01A3070001000000015F605F000000000A000000E80300002D0000000A000000323031333A30333A30342031363A30353A323400323031333A30333A30342031363A30353A32340003000000010..."