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%,那就展示一條(告警)消息.
| 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="<?<span id="1_nwp" style="width: auto; height: auto; float: none;"><a id="1_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=19&is_app=0&jk=d38684659f046a0d&k=php&k0=php&kdi0=0&luki=7&mcpm=0&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=d6a049f658486d3&ssp2=1&stid=0&t=tpclicked3_hc&td=1922429&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F4320%2Ehtml&urlid=0" target="_blank" mpid="1" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">php</span></a></span>?echo?$SERVER['PHP_SELF'];?>?"> Upload?image:? <input?type="file"?name="<span id="2_nwp" style="width: auto; height: auto; float: none;"><a id="2_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=19&is_app=0&jk=d38684659f046a0d&k=img&k0=img&kdi0=0&luki=6&mcpm=0&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=d6a049f658486d3&ssp2=1&stid=0&t=tpclicked3_hc&td=1922429&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F4320%2Ehtml&urlid=0" target="_blank" mpid="2" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">img</span></a></span>"?id="img"?/> <input?type="submit"?value="Sumit?Image"?/> </form> |
總結
請記得,PHP不能夠檢測所有的裸體圖片,所以不完全可信.我希望你覺得這還有點用處.
原文地址:http://www.rrpowered.com/2014/04/prevent-uploads-of-adult-or-nude-pictures-using-php/
轉載于:https://www.cnblogs.com/echohao/p/4971000.html
總結
以上是生活随笔為你收集整理的PHP 如何阻止用户上传成人照片或者裸照的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 东方国信是做什么的
- 下一篇: 银行卡16位19位区别