<!DOCTYPE html>
<html>
<title>test</title>
<body>
<form enctype="multipart/form-data" action="test.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="102400" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
</body>
</html>1.通過$_FILES['userfile']['type'];獲取文件后綴名;

創(chuàng)新互聯(lián)公司主營漢中網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app開發(fā)定制,漢中h5重慶小程序開發(fā)公司搭建,漢中網(wǎng)站營銷推廣歡迎漢中等地區(qū)企業(yè)咨詢
$data = $_FILES['userfile'];
var_dump($data);
/**結(jié)果**/
/*
array(5) {
["name"]=>
string(8) "test.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(26) "/private/var/tmp/phpfyE3EC"
["error"]=>
int(0)
["size"]=>
int(19)
}
*/沒有檢測(cè)出來;
2.用pathinfo()函數(shù)來獲取文件路徑的信息
$data = $_FILES['userfile'];
// var_dump($data);
var_dump(pathinfo($data['name']));
/**結(jié)果**/
/*
array(4) {
["dirname"]=>
string(1) "."
["basename"]=>
string(8) "test.jpg"
["extension"]=>
string(3) "jpg"
["filename"]=>
string(4) "test"
}
*/沒有檢測(cè)出來;
3.PHP的擴(kuò)展fileinfo(需要安裝開啟)
$data = $_FILES['userfile']; $filename = $data['tmp_name']; $finfo = finfo_open(FILEINFO_MIME_TYPE);//返回 mime 類型。 自 PHP 5.3.0 可用。 $mimetype = finfo_file($finfo, $filename); finfo_close($finfo); var_dump($mimetype); /**結(jié)果**/ //string(10) "text/plain"
以上就是PHP識(shí)別文件偽裝(文件上傳)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注創(chuàng)新互聯(lián)其它相關(guān)文章!
當(dāng)前標(biāo)題:php中文件上傳時(shí)如何驗(yàn)證上傳的文件是否合法?
文章源于:http://www.chinadenli.net/article14/iiidde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、微信小程序、標(biāo)簽優(yōu)化、商城網(wǎng)站、網(wǎng)站建設(shè)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)