首页 > 解决方案 > Imagen、HEX 到 Byte 和 Byte 到 HEX 并显示 img。Visual Basic 到 PHP

问题描述

我必须将 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 并打包

<?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;

?>

标签: phpvb6vb6-migration

解决方案


视觉功能不会生成原始的 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;
}

推荐阅读