时间:2021-07-01 10:21:17 帮助过:11人阅读
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>