PHP:二进制图像数据,检查图像类型 [英] PHP : binary image data, checking the image type

查看:116
本文介绍了PHP:二进制图像数据,检查图像类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在bin中有一些图像,我想检查标题以检查格式(jpg,png等)

I have some images in bin, I want to check the header to check the format (jpg, png, etc)

我不想使用temp文件!我有一个使用TEMP FILES的解决方案。

I don't want to use temp files! I have a solution using TEMP FILES.

推荐答案

这些位以:

$JPEG = "\xFF\xD8\xFF"
$GIF  = "GIF"
$PNG  = "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
$BMP  = "BM"
$PSD  = "8BPS"
$SWF  = "FWS"

其他我现在不知道的,但是大3(jpeg,gif,png)通常覆盖99%。因此,将第一个字节与那些字符串进行比较,就可以得到答案。

The other ones I wouldn't know right now, but the big 3 (jpeg,gif,png) usually cover 99%. So, compare the first bytes to those string, and you have your answer.

这篇关于PHP:二进制图像数据,检查图像类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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