Hex to Image Coverage in PHP?

I am developing a mobile application that negotiates with the server through PHP Webservice. This is my first experience using PHP. I was able to load data into a database. Now I need to send the image in order to save it on the ftp server. To do this, I converted image->hexand sent from my application.

Server side

I got the hex code, but not sure how to convert it to an image and save it on an FTP server. I am really fighting here. I was looking for him, but could not find the exact one.

Any help is greatly appreciated.

+3
source share
2 answers

Convert HEX string to binary:

$binary = pack("H*", $hex);

pack("H*", ...)equivalently hex2bin, which is available with PHP 5.4.

Burn it to disk:

file_put_contents("file.png", $binary);
+7

, , . , .

<?php  

    $hexpic=".......................
    .....................";

    # convert the hex string to binary

    $data = pack("H" . strlen($hexpic), $hexpic);

    #write the binary string into an image file

    file_put_contents("sample.png", $data);
?>
0

All Articles