사용자가 이미지를 제출하고 서버에 업로드 할 수 있도록 PHP 코드를 작성합니다. 나는 그것이 작동하게하고 서버가 이미지를받습니다. 그러나 서버가 .avi 및 .flv 파일을 받아들이는 것처럼 보입니다. 파일이 이미지인지 여부를 확인하기 위해 if/else 문을 쓰지만 작동하지 않는 이유는 무엇입니까? 당신내 업로드 이미지 코드에서 avi 및 flv 파일을 허용하는 이유
감사이이 행의 코멘트는 내 PHP 코드
$tmpPath = $_FILES["image"]["tmp_name"];
$movedPath = "submit-img/" . $_POST["category"] . "/" . $_FILES["image"]["name"];
$fullURL = parse_url($_SERVER['HTTP_REFERER']);
$query = explode("&", $fullURL["query"]); //only choose first query
$prevPage = "gallery.php" . "?" . $query[0];
//I get the file type here
$fileType = strpos($_FILES["image"]["type"], "image/");
//if its not an image then redirect to the previous page and send a message
if ($fileType === false || ($_FILES["image"]["size"]) == 0 || $_FILES["image"]["size"]/1024 > 5000){
$prevPage = $prevPage . "&imgSubmit=none#imgSubmitForm";
header("Location: " . $prevPage);
}else if ($_FILES["image"]["size"] > 0){ //if file is an image
if (!is_file($movedPath)){
move_uploaded_file($tmpPath, $movedPath);
}else{
while (is_file($movedPath)){
$extension = strrchr($movedPath, ".");
$movedPath = str_replace($extension, "", $movedPath) . "1" . $extension;
}
move_uploaded_file($tmpPath, $movedPath);
}
$prevPage = $prevPage . "&imgSubmit=submitted#imgSubmitForm";
header("Location: " . $prevPage);
}
이미지 만 필터링하고 있습니까? – javajavajava
가능한 복제본 [파일 업로드 제한 특정 파일 형식] (http://stackoverflow.com/questions/6099968/file-upload-restrict-certain-file-type) –
파일이 있는지 여부 만 확인하는 것 같습니다. 확장자 및 파일 크기가 0이 아니고 5MB 미만인지 여부를 지정합니다. 어떤 파일도 업로드 할 수 있습니다. – Wug