在 PHP 中将十六进制转换为图像? [英] Coverting Hex to Image in PHP?

查看:55
本文介绍了在 PHP 中将十六进制转换为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发通过 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.

非常感谢任何帮助.

推荐答案

将 HEX 字符串转换为二进制:

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 中将十六进制转换为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆