Coverting Hex to Image in PHP?

I am developing mobile app which talks with server via PHP Webservice. This is my first time using PHP. I managed to upload data in to database. Now i need to send an image to store it in ftp server. For that i converted image->hex and sent from my app.

Server Side

I got the hex code but not sure how to convert it in to an image and store in in ftp server. I am really struggling here. I googled it but couldn't find exact one.

Any help is much appreciated.


Convert the HEX string to binary:

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

pack("H*", ...) is equivalent to hex2bin, which is available since PHP 5.4.

Write it to disk:

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