您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP 如何阻止用户上传成人照片或者裸照

2026/2/7 9:29:32发布13次查看
在这份教程中,我们将会学习到如何组织用户通过php上传成人照片或者裸照.
我在phpclasses.org上面偶然发现一个很有用的,由bakr alsharif开发的可以帮助开发者基于皮肤像素点来检测图片裸照的类文件.
它会分析在一张图片的不同部分使用的颜色,并决定其是否匹配人类皮肤颜色的色调.
作为分析的结果,他会返回一个反映图片包含裸露的可能性的分值.
此外,他还可以输出被分析的图片,上面对使用给定颜色的肤色的像素进行了标记.
当前它可以对png,gif和jpeg图片进行分析.
php
下面展示了如何使用这个php类.
让我们先从包含裸体过滤器,nf.php文件开始.
include ('nf.php');
接下来,创建一个新的名叫imagefilter的类,然后把它放到一个叫做$filter的变量中.
$filter = new imagefilter;
获取图片的分值并将其放到一个$score变量中.
$score = $filter -> getscore($_files['img']['tmp_name']);
如果图片分值大于或等于60%,那就展示一条(告警)消息.
if($score >= 60){/*message*/}
下面是所有的php代码:
<?php/*include the nudity filter file*/include ('nf.php');/*create a new class called $filter*/$filter = new imagefilter;/*get the score of the image*/$score = $filter -> getscore($_files['img']['tmp_name']);/*if the $score variable is set*/if (isset($score)) {/*if the image contains nudity, display image score and message. score value if more
than 60%, it is considered an adult image.*/if ($score >= 60) { echo image scored . $score . %, it seems that you have uploaded a nude picture.;/*if the image doesn't contain nudity*/    } else if ($score < 0) { echo "congratulations, you have uploaded an non-nude image.";
}
}?>
标记语言
我们可以使用一个基础的html表单上传图片.
<form method="post" enctype="multipart/form-data" action="<?php echo $server['php_self'];?> >upload image:
<input type="file" name="img" id="img" /><input type="submit" value="sumit image" /></form>
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product