0
在PHP我有我的文件上傳代碼是這樣的PHP文件上傳
$image_name= $_FILES['file']['name'];
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else {
move_uploaded_file($_FILES['file']['tmp_name'], $tmpName.$image_name);
}
}
下面這段代碼工作正常,當我在做上傳。但它不適用於文件類型驗證。我只使用 $allowedExts = array("gif", "jpeg", "jpg", "png"); to use only these types of file to upload. But this one is uploading any files type. So can someone kindly tell me where is the wrong part here. I want to upload only
「gif」,「jpeg」,「jpg」,「png」文件。任何幫助和建議將非常令人欣喜。謝謝。