Home > php教程 > php手册 > php 判断文件上传类型与过滤不安全数据

php 判断文件上传类型与过滤不安全数据

WBOY
Release: 2016-06-13 11:23:13
Original
1462 people have browsed it

php教程 判断文件上传类型与过滤不安全数据

这函数 过滤不安全字符

function s_addslashes($string, $force = 0) {
 if(!get_magic_quotes_gpc()) {
  if(is_array($string)) {
   foreach($string as $key => $val) {
    $string[$key] = s_addslashes($val, $force);
   }
  } else {
   $string=str_replace("","& # x",$string); //

过滤一些不安全字符
   $string = addslashes($string);
  }
 }
 return $string;
}

实例:
$_COOKIE = c_addslashes($_COOKIE);
$_POST   = c_addslashes($_POST);
$_GET   = c_addslashes($_GET);

在公共文件中加入

if($_FILES){ 
 foreach( $_FILES as $key => $_value )
 {
  $_FILES[$key]['type'] =$_value['type'];  
 }
 if(substr($_FILES[$key]['type'],0,6) !='image/')
 {
  exit;
 }
}

禁止上传除图片文件以外的文件,
提示:
不要获取文件扩展名来判断类型,这样是最不安全的,我们用$_FIlES['form']

['type']
这个可以读取文件内容来识别文件类型,但它能识别的有限,不过如果你用图片就足

够了解。

www.111cn.cn 本站原创,转载注明


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template