PHP 如何阻止用戶上傳成人照片或者裸照
在這份教程中,我們將會(huì)學(xué)習(xí)到如何阻止用戶通過PHP上傳成人照片或者裸照.
示例 下載
我在phpclasses.org上面偶然發(fā)現(xiàn)一個(gè)很有用的,由Bakr Alsharif開發(fā)的可以幫助開發(fā)者基于皮膚像素點(diǎn)來檢測(cè)圖片裸照的類文件.
它會(huì)分析在一張圖片的不同部分使用的顏色,并決定其是否匹配人類皮膚顏色的色調(diào).
作為分析的結(jié)果,他會(huì)返回一個(gè)反映圖片包含裸露的可能性的分值.
此外,他還可以輸出被分析的圖片,上面對(duì)使用給定顏色的膚色的像素進(jìn)行了標(biāo)記.
當(dāng)前它可以對(duì)PNG,GIF和JPEG圖片進(jìn)行分析.
PHP下面展示了如何使用這個(gè)PHP類.
讓我們先從包含裸體過濾器,nf.php文件開始.
include ('nf.php');
接下來,創(chuàng)建一個(gè)新的名叫ImageFilter的類,然后把它放到一個(gè)叫做$filter的變量中.
$filter = new ImageFilter;
獲取圖片的分值并將其放到一個(gè)$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."; }}?>標(biāo)記語(yǔ)言
我們可以使用一個(gè)基礎(chǔ)的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>總結(jié)
請(qǐng)記得,PHP不能夠檢測(cè)所有的裸體圖片,所以不完全可信.我希望你覺得這還有點(diǎn)用處.
原文地址:http://www.rrpowered.com/2014/04/prevent-uploads-of-adult-or-nude-pictures-using-php/
相關(guān)文章:
1. 解析原生JS getComputedStyle2. Idea 2019.3 本應(yīng)該搜索到的插件卻搜索不到的解決方法3. SpringBoot+SpringCache實(shí)現(xiàn)兩級(jí)緩存(Redis+Caffeine)4. IntelliJ IDEA安裝插件的方法步驟5. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法6. ASP.NET MVC視圖頁(yè)使用jQuery傳遞異步數(shù)據(jù)的幾種方式詳解7. ASP.NET泛型三之使用協(xié)變和逆變實(shí)現(xiàn)類型轉(zhuǎn)換8. IntelliJ IDEA導(dǎo)入jar包的方法9. 每日六道java新手入門面試題,通往自由的道路10. 每日六道java新手入門面試題,通往自由的道路--多線程
