php 读取文件头部两个字节 判断文件的实际类型
function checkFileType($fileName){
$file = fopen($fileName, "rb");
$bin = fread($file, 2); //只读2字节
fclose($file);
$strInfo = @unpack("C2chars", $bin);// C为无符号整数,网上搜到的都是c,为有符号整数,这样会产生负数判断不正常
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
$fileType = '';
if($typeCode == 255216 /*jpg*/ || $typeCode == 7173 /*gif*/ || $typeCode == 13780 /*png*/) {
return true;
}else{
return false;
}
}
相关文档:
PHP]
;;;;;;;;;;;
; WARNING ;
;;;;;;;;;;;
; This is the default settings file for new PHPinstallations.
; By default, PHP installs itself with a configuration suitablefor
; development purposes, and *NOT* for production purposes.
; For several security-oriented considerations that should betak ......
这是一些使用频率比较高的函数,有的来自别人的程序......
1.产生随机字符串函数
function random($length) {
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($ ......
自己编写基于MVC的轻量级PHP框架
2008-4-3 23:33:56 已被阅读:
477 发表评论
做WEB开发已有一年,每次都写重复的东西, 因此,想自己写一下框架,以后开发方便.
本人之前学习asp.NET两年,JSP半年,可是后来因为工作的原故换成PHP.其实很不喜欢PHP的语法.还有PHP的函数名,每回都忘记..还是喜
欢C#和JAVA的语法,哈...不 ......
以下是利用php实现中文水印的代码。
<?php
Header("Content-type: image/png"); /*通知浏览器,要输出图像*/
$im = imagecreate(400 , 300); /*定义图像的大小*/
$gray = Ima ......
这是我最近几天的学习心得,与大家共享。
1,一般情况下我们用记事本写一个简单的PHP页面,放在Apache服务器安装目录下的htdocs目录下,即可访问。
这时,在httpd.conf文件中对应的服务器根目录配置为:DocumentRoot "D:/Apache Software Foundation/Apache2.2/htdocs"
目录配置为:<Directory "D:/Apache Software F ......