PHP 关于 图片mime 格式的判断

WBOY
Release: 2016-06-23 13:32:50
Original
1268 people have browsed it

JPEG(JFIF)文件从第6个字节开始,连续读5个字节,值为:  0x4A46494600,

但是,我的判断总是返回false,求解!

$bytes = file_get_contents('1.jpg', null, null, 5, 5);echo $bytes == "\x4A\x46\x49\x46\x00"; // 这里总是返回falseecho "\x4A\x46\x49\x46\x00"; // 会显示 JFIF,以及一个看不见的控制字符\0
Copy after login


如果用strpos查找这5个字节中是否含有JFIF,是可以的,但我想用 == 来判断,难道 == 运算符对这个运算不起作用吗?

求解!


回复讨论(解决方案)

$bytes = file_get_contents('1.jpg', null, null,  6, 5);
谁跟你说是第六个啦?
echo $bytes;
看看不就知道啦

$bytes = file_get_contents('1.jpg', null, null,  6, 5);
谁跟你说是第六个啦?
echo $bytes;
看看不就知道啦



呃,我数错了。。。

感谢版主大人!
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!