从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.

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.