PHP 如何阻止使用者上傳成人照片或者裸照,_PHP教程

來源:互聯網
上載者:User

PHP 如何阻止使用者上傳成人照片或者裸照,


 在這份教程中,我們將會學習到如何阻止使用者通過PHP上傳成人照片或者裸照.

  樣本 下載

  我在phpclasses.org上面偶然發現一個很有用的,由Bakr Alsharif開發的可以協助開發人員基於皮膚像素點來檢測圖片裸照的類檔案.

  它會分析在一張圖片的不同部分使用的顏色,並決定其是否匹配人類皮膚顏色的色調.

  作為分析的結果,他會返回一個反映圖片包含裸露的可能性的分值.

  此外,他還可以輸出被分析的圖片,上面對使用給定顏色的膚色的像素進行了標記.

  當前它可以對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%,那就展示一條(警示)訊息.

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

  下面是所有的PHP代碼:

123456789101112131415161718 /*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表單上傳圖片.

12345

  總結

  請記得,PHP不能夠檢測所有的裸體圖片,所以不完全可信.我希望你覺得這還有點用處.

  原文地址:http://www.rrpowered.com/2014/04/prevent-uploads-of-adult-or-nude-pictures-using-php/




http://www.bkjia.com/PHPjc/885997.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/885997.htmlTechArticlePHP 如何阻止使用者上傳成人照片或者裸照, 在這份教程中,我們將會學習到如何阻止使用者通過PHP上傳成人照片或者裸照. 樣本 下載 我在php...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.