我编写 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);
}