2014-04-01 4 views
-2

여러 이미지를 업로드하는 데이 코드를 사용하고 있습니다. 공격을 막기 위해 이미지 살균 코드를 추가하고 싶습니다. 또한 업로드 된 파일의 이름을 md5 해시 알고리즘을 사용하여 고유 한 이름으로 바꾸고 싶습니다. 어떻게 할 수 있습니까? 나는 이러한 PHP를 사용하여 업로드 된 여러 이미지 업로드

<?php 

if($_SERVER['REQUEST_METHOD'] == "POST") 
if(isset($_FILES['file'])) 
{ 
$count = 0; 
$errors= array(); 
foreach($_FILES['file']['tmp_name'] as $key => $tmp_name) 
{ 
$file_name = $key.$_FILES['file']['name'][$key]; 
$file_size =$_FILES['file']['size'][$key]; 
$file_tmp =$_FILES['file']['tmp_name'][$key]; 
$file_type=$_FILES['file']['type'][$key]; 

$size = getimagesize($_FILES['file']['tmp_name'][$key]); 
if ($size === FALSE) { 
die("Oopz,This is not an image"); 
} 


$enc_id= $_POST['form_id'].$_POST['name3']; 
$md5folder = md5($enc_id); 
$upload_path ="uploads/".$md5folder; 

if(!is_dir($upload_path)) 
{ 
mkdir($upload_path, 0777, true); 
} 

if(empty($errors)==true) 
    { 
move_uploaded_file($file_tmp,$upload_path.'/'.$file_name); 
    } 

} 
?> 

이 또한 내가 수행하는 코드의이 부분은 어떤 의미가 알고 싶어 .. 좀 도와 things..Please합니까?

$size = getimagesize($_FILES['file']['tmp_name'][$key]); 
if ($size === FALSE) { 
die("Oopz,This is not an image"); 
} 

답변

0

사용이 데이터베이스 입력을 살균하기 :

$image = "image1.jpg"; 
$filehash = md5($image); 
:

function cleanInput($input) { 

$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript 
'@<[\/\!]*?[^<>]*?>@si',   // Strip out HTML tags 
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly 
'@<![\s\S]*?--[ \t\n\r]*>@'   // Strip multi-line comments 
); 

$output = preg_replace($search, '', $input); 
return $output; 
} 
?> 
<?php 
function sanitize($input) { 
if (is_array($input)) { 
    foreach($input as $var=>$val) { 
     $output[$var] = sanitize($val); 
    } 
} 
else { 
    if (get_magic_quotes_gpc()) { 
     $input = stripslashes($input); 
    } 
    $input = cleanInput($input); 
    $output = mysql_real_escape_string($input); 
} 
return $output; 
} 

사용 이것은 단지 파일 이름 MD5 해시를 계산

관련 문제