在PHP中上传的图像没有文件扩展名


Uploaded image in PHP not getting a file extension

文件已上传并移动到正确的位置,但该文件将成为无法识别的文件类型(type="file")

这是我的脚本:

//choose name for picture
$__img_name = "";
$query = "SELECT MAX(number) FROM post";
$stmt = $con->prepare($query);
$stmt->execute();
$stmt->bind_result($number);
$rows = $stmt->num_rows;
if($rows > 0){
    $__img_name = $number;
} else{
    $__img_name = 1;
}
//moving file to specific place
$__route = '../app/images/uploads/';
$validextensions = array("jpeg", "jpg", "png");
$temp = explode(".", $_FILES["image"]["name"]);
$extension = end($temp);
if ((($_FILES["image"]["type"] == "image/jpeg")
    || ($_FILES["image"]["type"] == "image/jpg")
    || ($_FILES["image"]["type"] == "image/png"))
    && in_array($extension, $validextensions)
) {
    move_uploaded_file($_FILES['image']['tmp_name'], $__route . $__img_name . $extension);
}

当我print_r() $_FILES对象时,下面是输出:

array (size=1)
  'image' => 
    array (size=5)
      'name' => string 'braum_poro_by_proxy_oq-d7i83tv.png' (length=34)
      'type' => string 'image/png' (length=9)
      'tmp_name' => string 'C:'wamp'tmp'phpC09C.tmp' (length=23)
      'error' => int 0
      'size' => int 265229

是什么导致文件无法识别?

您错过了点..将$__route . $__img_name . $extension更改为$__route . $__img_name."." . $extension