dop82210 2012-03-15 19:21
浏览 54
已采纳

从DB到浏览器以十六进制显示图像

I have an image (jpeg) stored in my DB (SQL Server) and when I read it I got a hex code. But I can't display it to the browser, it doesn't understand and shows the pure code.

Here's a hex code example

I need help to achieve this. Thank you all in adv.

  • 写回答

1条回答 默认 最新

  • douxiangui5011 2012-03-15 19:56
    关注

    If you have PHP >= 5.4 you can use hex2bin().

    If not you can use the alternative function posted on that page:-

    /**
     * Converts the hex representation of data to binary
     *
     * http://www.php.net/manual/en/function.hex2bin.php
     *
     * @param   string  $str        Hexadecimal representation of data
     *
     * @return  string              Returns the binary representation of the given data
     */
    public function hex2bin($data)
    {
        $bin    = "";
        $i      = 0;
        do {
            $bin    .= chr(hexdec($data{$i}.$data{($i + 1)}));
            $i      += 2;
        } while ($i < strlen($data));
        return $bin;
    }
    

    Then you just set your headers and echo the result out to the browser.

    You'd be surprised what you can learn just by looking at the PHP manual. Hopefully, this will work for you, or at least set you on the right track.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器