Imagen,将HEX转换为Byte,将Byte转换为HEX并显示img。 Visual Basic到PHP

时间:2018-10-08 19:16:25

标签: php vb6 vb6-migration

我必须将Visual Basic中的函数传递给PHP才能读取保存在MySQL中的图像。 我已经尝试了几件事,但是我没有做 当前保存在数据库MySql中:https://www.pastiebin.com/5bbba9dbc63f6#&togetherjs=73xi1xwALu

    'Save string a Byte in MySql
Public Function StringaByte(cTexto As String) As Byte()
Dim aByte() As Byte
Dim aHexa() As String
Dim i As Long

aHexa = Split(cTexto, "&H")
ReDim aByte(UBound(aHexa) + 1) As Byte
For i = 0 To UBound(aHexa) - 1  
    DoEvents
    aByte(i) = CLng("&H" & aHexa(i + 1))  
Next

StringaByte = aByte
End Function  

'Load hexa in MySql an conver to Byte
Private Function ByteaString(aByte() As Byte) As String
Dim i As Long
Dim cHex As String
cHex = ""
For i = 0 To UBound(aByte)
    DoEvents
    cHex = cHex & "&H" & Hex(aByte(i))    
Next

ByteaString = cHex 
End Function

在PHP中,我尝试了功能hex2bin和pack

<?php
//header("Content-type: image/gif"); 
header("Content-type: image/jpg"); 

$img2="CODE HEXA IN LINK";

function hextobin($hexstr){ 
    $aHexa = explode("&H", $hexstr);
    $count=count($aHexa);  
    $aByte="";
    for ($x=0;$x<$count; $x++){
        @$aByte .="&H".hex2bin($aHexa[$x]);
    }
    return $aByte;
 }  

$acomulo= hextobin($img2) ;
echo base64_decode($acomulo);exit; 
//echo $acomulo;exit; 

?>

PHP中的其他示例

 <?php
$img2="CODE HEXA IN LINK";

    function hextobin($hexstr) {
        $aHexa = explode("&H", $hexstr);
        $count = count($aHexa);
        $aByte = "";
        for ($x = 0; $x < $count; $x++) {;
            @$aByte .=pack("H*", $aHexa[$x]);
        }
        return @$aByte;
    }
    $acomulo = hextobin($img2);
    header("Content-type: image/gif");
    echo base64_decode($acomulo);
    exit;

?>

1 个答案:

答案 0 :(得分:0)

视觉功能不会生成原始的100%十六进制。

function vb6toIMG($func_string){
$func_string=substr($func_string,2);
    //die($func_string);

    $arrayHex=explode ("&H",$func_string);
    $str="";
    foreach($arrayHex as $ind=>$dato){
            $str.=chr(hexdec($dato));
    }   
        return $str;
}