Я пишу php-код, чтобы пользователь мог отправить изображение и загрузить его на сервер. Я заставляю его работать, и сервер получает изображение. Но вроде сервер принимает даже файлы .avi и .flv. Я пишу оператор if/else для проверки того, является ли файл изображением, но почему он не работает? Спасибо
Это мой 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);
}