问题描述
我正在开发通过PHP Webservice
与服务器通信的移动应用程序.这是我第一次使用PHP.我设法将数据上传到数据库中.现在,我需要发送图像以将其存储在ftp服务器中.为此,我转换了image->hex
并从我的应用程序发送了它.
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.
服务器端
我得到了十六进制代码,但不确定如何将其转换为图像并存储在ftp服务器中.我在这里真的很挣扎.我用谷歌搜索,但找不到确切的数字.
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.
非常感谢您的帮助.
推荐答案
将十六进制字符串转换为二进制:
Convert the HEX string to binary:
$binary = pack("H*", $hex);
pack("H*", ...)
等效于 hex2bin
,自PHP 5.4起可用.
pack("H*", ...)
is equivalent to hex2bin
, which is available since PHP 5.4.
将其写入磁盘:
file_put_contents("file.png", $binary);
这篇关于在PHP中将Hex转换为Image?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!