文件上传时通知用户

时间:2018-09-20 20:03:33

标签: php sql image mysqli file-upload

当文件上传后,我想在UPDATE语句的正下方显示一条消息,但是我在语法上苦苦挣扎。完整代码:

if (empty($_FILES['image']['name']))
    {
      header('location:perfil.php?error=1');
      return;
    }
else if (!in_array($_FILES['image']['type'], $formatos))
    {
      header('location:perfil.php?error=2');
      return;
    }
else if (in_array($_FILES['image']['type'], $formatos)) 
{
    if( mysqli_num_rows($todas_fotos) > 0) {
        mysqli_query($conexao,"UPDATE esc_usuarios_fotos SET img_local = '$location' WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");

                if (move_uploaded_file($_FILES["image"]["tmp_name"],"images/perfis/" . $newFilename)){
        header('location:perfil.php');
    }
    }
    else {
        mysqli_query($conexao,"insert into esc_usuarios_fotos (img_local, img_usu_codigo) values ('$location', '" . $_SESSION['codigo'] . "')");
    }
    header('location:perfil.php');
}

有什么想法吗?

编辑:

这些是上传参数:

    $fileinfo=PATHINFO($_FILES["image"]["name"]);
$newFilename=$fileinfo['filename'] ."_". time() . "." . $fileinfo['extension'];
move_uploaded_file($_FILES["image"]["tmp_name"],"images/perfis/" . $newFilename);
$location="images/perfis/" . $newFilename;
$todas_fotos = mysqli_query($conexao, "SELECT * FROM esc_usuarios_fotos WHERE 
img_usu_codigo = '" . $_SESSION['codigo'] . "'");

$formatos = array('image/jpeg', 'image/png');/*

0 个答案:

没有答案