PHP - 上传的文件名是EMPTY enctype集

时间:2013-10-10 16:54:36

标签: php html

这是我的HTML:

  <form name = "picture" action = "upload.php" method="post" enctype="multipart/form-data">
  <input type="file" name="poza" id = "profilh" onmouseover="profilehov()" onmouseout="profileleave()" onchange="javascript:document.forms['picture'].submit();"></form>

这是我的php:

   $profile = $_POST['poza'];
   if($profile){
   $add = $profile['poza']['name'];
   $userem = $info['email'];
   $allowedExts = array("gif", "jpeg", "jpg", "png");
   $check = explode(".",$add);
   $extension = end($check);
   if((($_FILES['poza']['type']=="image/gif")||($_FILES['poza']['type']=="image/jpeg")||($_FILES['poza']['type']=="image/jpg")||($_FILES['poza']['type']=="image/png") &&($_FILES['poza']['size']<51000))&& in_array($extension,$allowedExts)){
    if(file_exists("uploads/".ENCRYPTION($userem)."/".$add)){
        $errors+=1;
    }
   if($errors == 0){
move_uploaded_file($_FILES['poza']['tmp_name'],"uploads/".ENCRYPTION($userem)."/".$add);
$sql1 = "UPDATE **** SET ****= **** WHERE **** = ****";
$res1 = mysqli_query(****,$sql1) or die (mysqli_error(****));
}
    }
     }

我遇到的问题是$ add变量是空的....为什么?

P.S:其他一切似乎都很好。

1 个答案:

答案 0 :(得分:0)

$add = $profile['poza']['name'];

错了。使用$_FILES全局:

$add = $_FILES['poza']['name'];

检索表单字段poza中的文件名称。

同样,

$_FILES['poza']['tmp_name']

是本地文件名。