2014-11-16 1 views
0

그래서이 파일 업로드 시스템은 $ allowedExts의 파일 유형 만 받아 들일 예정이지만 어떤 사람은 angel.jpg.php라는 파일로 시스템을 계속 위반합니다. 나는 그가 MIME 형식을 변경했다고 생각하지만, 나는 그가 확장 검사를 어떻게 위반했는지 아직도 궁금해하고있다. 도움을 주시면 감사하겠습니다. 미리 감사드립니다.PHP 안전 업로드 시스템

<?php  
$allowedExts = array("gif", "jpeg", "jpg", "png", "bmp", "doc", "pages", "docx", "pdf","ppt","pptx","xls","xlsx"); 

$temp = explode(".", $_FILES["file"]["name"]); 
$extension = end($temp); 
$extension2 = pathinfo($target_file,PATHINFO_EXTENSION); 

if (($_FILES["file"]["type"] == "image/gif") 
|| ($_FILES["file"]["type"] == "image/jpeg") 
|| ($_FILES["file"]["type"] == "image/jpg") 
|| ($_FILES["file"]["type"] == "image/pjpeg") 
|| ($_FILES["file"]["type"] == "image/x-png") 
|| ($_FILES["file"]["type"] == "image/png") 
|| ($_FILES["file"]["type"] == "image/bmp") 
|| ($_FILES["file"]["type"] == "application/msword") 
|| ($_FILES["file"]["type"] == "application/x-iwork-pages-sffpages") 
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") 
|| ($_FILES["file"]["type"] == "application/pdf") 
|| ($_FILES["file"]["type"] == "application/vnd.ms-powerpoint") 
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation") 
|| ($_FILES["file"]["type"] == "application/excel") 
|| ($_FILES["file"]["type"] == "application/vnd.ms-excel") 
|| ($_FILES["file"]["type"] == "application/x-excel") 
|| ($_FILES["file"]["type"] == "application/x-msexcel") 
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") 
&& in_array($extension, $allowedExts) && in_array($extension2, $allowedExts) && getimagesize($_FILES["file"]["name"])!=='FALSE') 
{ 
// Upload file 
} 

else { 
// Do not upload file 
} 
+2

확장에 대한 조건이 &&는'만 MIME 형식 조건의 마지막에 -linked'때문에 당신의 논리는, 결함이 때문에'&&' '||'보다 더 높은 우선 순위를가집니다. 모든'||'- 연결된 조건들에 다른 괄호를 써야합니다. – CBroe

+0

$ _FILES [ "file"] [ "type"]을 변수 – Riad

+0

에 넣음으로써 논리적 조건을 최소화하려고 시도합니다. 그리고 이러한 모든 이미지가없는 mime 유형을'getimagesize'와 결합하는 것은별로 의미가 없습니다 - 나는' getimagesize'는 fe를 체크하게하면'false'를 반환합니다. 엑셀 문서. – CBroe

답변