我正在嘗試檢查在我的多個輸入字段中,圖像是否真的是圖像。問題是,我的代碼仍然允許上傳 pdf 和其他文件。我在這里閱讀了有關(guān)它的問題,但這不是我發(fā)現(xiàn)的唯一東西,但我真的不明白我應(yīng)該如何使用它。這是它的樣子:$selectid = $conn->prepare("SELECT max(id) AS id FROM cards");$selectid->execute();$cardid = $selectid->get_result()->fetch_array()['id'];$stmt = $conn->prepare("INSERT INTO cardimages(image, cardid) VALUES(?, ?)");$target_file = $_FILES['file']['tmp_name'];$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"&& $imageFileType != "gif" ) {echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";}if (count($_FILES['file']['tmp_name']) > 5) { header("Location: addbusiness.php?message=3");} else { $everyPicUnder2Mb = true; for ($i = 0; $i < count($_FILES['file']['tmp_name']); $i++) { if ($_FILES["file"]["size"][$i] > 2100000) { $everyPicUnder2Mb = false; } } if ($everyPicUnder2Mb) { for ($i = 0; $i < count($_FILES['file']['tmp_name']); $i++) { $file = $_FILES['file']['tmp_name'][$i]; if (is_uploaded_file($file)) { $imgData = file_get_contents($file); $stmt->bind_param("si", $imgData, $cardid); $stmt->execute(); } } } else { header("Location: addbusiness.php?message=2"); }}
檢查圖像的輸入文件類型
慕的地8271018
2022-11-04 17:15:28