PHPはどのようにユーザーが大人の写真やヌード写真をアップロードすることを阻止します

3655 ワード

このチュートリアルでは、PHPを通じて大人の写真やヌード写真をアップロードするのを阻止する方法を学びます.
サンプルのダウンロード
私はphpclassesにいます.orgの上で偶然1つのとても役に立つことを発見して、Bakr Alsharifによって開発した皮膚の画素の点に基づいてピクチャーのヌード写真の類のファイルを検出することを助けることができます.
1枚の画像の異なる部分で使用する色を分析し、人間の皮膚の色の色調に合うかどうかを決定します.
分析の結果、彼は画像が露出する可能性を反映するスコアを返す.
また、所定の色の肌の色を用いる画素にマーキングした分析画像を出力することもできる.
現在、PNG、GIF、JPEGの画像を分析することができる.
  PHP
このPHP類の使い方を以下に示す.
まずヌードフィルタを含むnf.phpファイルが開始します.
1 include  ( 'nf.php' );
次に、ImageFilterという新しいクラスを作成し、$filterという変数に配置します.
1 $filter   new   ImageFilter;
画像のスコアを取得し、$score変数に配置する.
1 $score   $filter   -> GetScore( $_FILES [ 'img' ][ 'tmp_name' ]);
画像のスコアが60%以上である場合、メッセージが表示される.
1
2
3 if ( $score   >= 60){ /*Message*/ }
以下はすべてのPHPコードです.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <?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フォームを使用して画像をアップロードすることができます.
1
2
3
4
5 <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>
まとめ
PHPはすべてのヌード画像を検出できないので、完全に信頼できないことを覚えておいてください.これはまだ役に立つと思います.