首页>>新闻中心>>PHP学习

判断上传文件的类型

来源: 本站    发布时间: 2014-11-03 22:10    阅读次数:

使用preg_match()函数进行正则表达式匹配。

创建index.php文件,当单击“上传”按钮时,利用preg_match()正则表达式函数上传的数据信息进行匹配并进行结果。其代码如下:

<?php

if($_POST[SUB]){

if(preg_match("/.jpg/",strtolower($_POST[text]))){

echo"上传为图片类型";

}else{

if(preg_match("/.rar/",strtolower($_POST[text]))){

echo "上传为压缩包类型";

}else{

echo "其他文件类型";

}

}

}

?>

一起设计吧
BACK