$file = fopen($picpath, "rb");
$bin = fread($file, 2); //只读2字节
fclose($file);
$strInfo = @unpack("c2chars", $bin);
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
print_r($strInfo);我读jpg的类型文件 返回问什么是: Array ( [chars1] => -1 [chars2] => -40 )
按网上的返回是:255216 ,而我却返回-1 请高手指点,这是为什么呢???
$bin = fread($file, 2); //只读2字节
fclose($file);
$strInfo = @unpack("c2chars", $bin);
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
print_r($strInfo);我读jpg的类型文件 返回问什么是: Array ( [chars1] => -1 [chars2] => -40 )
按网上的返回是:255216 ,而我却返回-1 请高手指点,这是为什么呢???
case 'ffd8': echo 'jpg';
break;
default: echo 'unknown';
}
if (is_uploaded_file($_FILES["$upfile"][tmp_name])){//判断是否有内容上传
//////////判断文件格式///////////
$file = fopen($_FILES["$upfile"][tmp_name], "rb");
$bin = fread($file,2); //只读10字节
fclose($file);
$strInfo = @unpack("c2chars", $bin);
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
//说明
// array("D0CF11E0","xls/doc"),
//array("504B0304","zip"),
//array("52617221","rar"),
if ($strInfo['chars1']=='-1'&& $strInfo['chars2']=='-40') {
$typeCode='255216';
}
if ($strInfo['chars1']=='-119'&& $strInfo['chars2']=='80') {
$typeCode='13780';
}
if(($typeCode=="7173") or ($typeCode=="255216") or ($typeCode=="6677")or ($typeCode=="13780")){
if($_FILES["$upfile"][size]<=$max_size){//3
switch($typeCode){
case 7173:$filename=$filename.".gif";break;
case 255216:$filename=$filename.".jpg";break;
case 6677:$filename=$filename.".bmp";break;
case 13780:$filename=$filename.".png";break;
}
copy($_FILES["$upfile"][tmp_name],$path.$filename); //检查是否上传成功else //文件超出限制时
file_exists($path.$filename);
$newfilename=$path_sql.$filename;/*3*/
return $newfilename;
} else{//9
echo "<script language=\"javascript\">\n";
echo "alert('只允许上传250KB内文件!');\n";
echo "history.back();\n";
echo "</script>";
exit;/*9*/}
}else{//5
echo "<script language=\"javascript\">\n";
echo "alert('只允许上传gif、jpg、bmp、png文件格式!');\n";
echo "history.back();\n";
echo "</script>";
exit;/*5*/}
}else{return $newfilename=$nowimgpic;}
}
////////////////////////函数调用结束////////////////////designerid