日期:2014-05-16  浏览次数:20947 次

php如何将图片gif,jpg或mysql longblob或blob字段值转换成16进制字符串!

php如何将图片gif,jpg或mysql longblob或blob字段值转换成16进制字符串!经过查找居然如此简单,一个函数就搞定了。

?

数据库脚本:

-- --------------------

--
-- 表的结构 `highot_attachment`
--

CREATE TABLE IF NOT EXISTS `highot_attachment` (
? `id` int(11) NOT NULL auto_increment,
? `phone_number_id` int(11) NOT NULL COMMENT 'phone_number表id',
? `highot_attachment` longblob NOT NULL COMMENT '附件',
? `filename` varchar(255) NOT NULL COMMENT '文件名',
? `attachment_type` int(2) NOT NULL COMMENT '附件类型',
? `attachment_title` varchar(255) NOT NULL COMMENT '附件描述',
? `userid` int(11) NOT NULL COMMENT '添加用户',
? `isdel` int(1) NOT NULL COMMENT '是否删除:1删除 0:正常',
? `create_dt` datetime NOT NULL COMMENT '添加日期',
? PRIMARY KEY? (`id`)
) ENGINE=InnoDB? DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

--
-- 转存表中的数据 `highot_attachment`
--

INSERT INTO `highot_attachment` (`id`, `phone_number_id`, `highot_attachment`, `filename`, `attachment_type`, `attachment_title`, `userid`, `isdel`, `create_dt`) VALUES
(4, 1, 0xffd8ffe000104a46494600010101006000600000ffdb0043000302020302020303030304030304050805050404050a070706080c0a0c0c0b0a0b0b0d0e12100d0e110e0b0b1016101113141515150c0f171816141812141514ffdb00430103040405040509050509140d0b0d1414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414ffc000110800b400b403012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00fd50d9cd3a968a0028a28a0028a28a0028a28a0028a28a0028a28a0028a66ff988c1e290c800271d3934ae0494544b387008ce29ab72acc54649155662b93d15099d4763d334c8ef63941c023eb45985fa1668a8cca001c13f4a5f33d8d4dc2f61f452039a5a630a28a2800a28a2800a28a2800a28a2800a28a2800a28a2800a28a2802191b69245795fc75fda13c35f01fc39fda1adcc26d42756363a544fb67bb60402173d00c8cb1e057a8ce76e4f4cf15f90bfb5b7c40d57c75f1dbc506fe77369a5dd3e9d6b6eec4a451a11b8a8e8371193eb81e82bc9ccb18f03439e2b56cfd038238663c5199fd5eacad4e0b9a56ddaecbd4f6cd5ff00e0a69afdc5f29d33c19636b6a09fdddcddb3c8e3dc850057b47c08fdbbbc33f14b588b45d72c7fe113d666654b659ee3ccb7b963d02bed1b58f656fccd791fc16fd833c35e36f859a7f8835bf105f8d4757b65b9845808c456a1b950720ef38eb9c0cf15f2c7c63f8677ff0006be20ea9e18baba8aea4b672d0dcdbca0ef8c9f90b60e51f6e32a7907f0af9f962b31c1a8d7adac65d3fafbcfd7a9641c13c4352ae5396a70af4eeb9bdedd3b37afc493d1decfaae87eaa7c6afda27c2ff0474396e75bb959752784cb67a4432817175ce3e51ce173c163c0c57c8daa7fc14cbc4136a0469de0ed3adec949c477576f24a7ea400057c81ad789f56f145d2dc6b1aa5dea972116dd65beb8690aa0e1572e7803f4eb5f6d7c33ff00827a787b5ef00586a3e21f115e8d6b52b58aed1f4cf2cdbdb6f5dc1573feb3823249c7a55ac6e37329b8e1172a473cf85385b833074aa711b75aa5476eb6dfa256d1756eefcba1e9df01ff006ecf0e7c59d7a2d0358d35bc2bacca42db196e4496f74707203606c6f456ebd8d7d4514de60c818e6bf11fc79e1893e1d7c46f106810df3cb268da94d6b1dea7cacc63930afc1f94f1d8f06bf5e3f67cd6af7c4bf05bc13aa5f4f25c5e5de936f24d34bcb3bece589f5279af4f2ac7d4c44a542b7c513e1f8f384f079253a199658daa357ecbd6d74e4ade56b6fa9e931f43ef4fa8a23c1eb9cd4b5f407e40145145030a28a2800a28a2800a28a2800a28a2800a6798b8cee181ef4eaaacd853b806c8ed409e84ad7118e37ae73d33486