How PHP prevents users from uploading adult photos or nude photos

Source: Internet
Author: User
Tags html form php class
In this tutorial, we will learn how to organize users to upload adult photos or nude photos via PHP.
I stumbled upon a very useful phpclasses.org that was developed by Bakr Alsharif to help developers detect nude photos of pictures based on their skin pixels.

It analyzes the colors used in different parts of a picture and determines whether they match the color tones of the human skin.

As a result of the analysis, he returns a score that reflects the likelihood that the image will contain nudity.

In addition, he can output images that have been analyzed, which mark the pixels of the skin color using a given color.

Currently it can analyze png,gif and JPEG images.

Php

The following shows how to use this PHP class.
Let's start with a nf.php file containing a nude filter.

Include (' nf.php ');


Next, create a new class called ImageFilter, and then put it in a variable called $filter.

$filter = new ImageFilter;


Gets the image's score and puts it into a $score variable.

$score = $filter getscore ($_files[' img '] [' tmp_name ']);


If the image score is greater than or equal to 60%, then a message is displayed.

if ($score  >= 60) {/*message*/}


Here is all the PHP code:

<?php/*include the nudity Filter file*/include (' nf.php ');/*create a new class called $filter */$filter = new Imagefilte R;/*get the score of the image*/$score = $filter-Getscore ($_files[' img ' [' tmp_name ']);/*if The $score variable is SE T*/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 >=) {echo "image scored". $score. "%, It seems that you had uploaded a nude picture."; *if the image doesn ' t contain nudity*/} else If ($score < 0) {echo "Congratulations, you had uploaded an non-nude im Age. ";
}
}?>


Markup language

We can upload images using a basic HTML form.

<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>

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.