$ _FILES undefined index error how to solve [duplicate]

1

When uploading an image I get the error:

  

Notice: Undefined index: image in C: \ Apache24 \ htdocs \ change_photo.php on line 9

     

Notice: Undefined index: image in C: \ Apache24 \ htdocs \ change_photo.php on line 10

Call:

<script type="text/javascript">
            $(document).ready(function(){

                $('#imagem').live('change',function(){
                    var url1 = "change_photo.php";
                    var email1 = "<?php echo $_SESSION['email']?>";
                    var fileVal=document.getElementById("imagem");
                    var fakeFile = fileVal.value;
                    $.post(url1,{postemail1:email1,foto:fakeFile},
                        function(result) {
                        $("#visualizar").html(result); // Só pra verificar retorno
                    });

                });
            }) 
</script>

Form:

<form id="formulario" method="post" enctype="multipart/form-data" action="change_photo.php">
        Foto
        <input type="file" id="imagem" name="imagem" /> 
    </form>

Change_photo.php:

 include('conexao.php');
 $pasta = "fotos/";

 /* formatos de imagem permitidos */ 
 echo $_POST['foto'];

 $permitidos = array(".jpg",".jpeg",".gif",".png", ".bmp");

    $name = $_FILES['imagem']['name'];
    $tmp_name = $_FILES['imagem']['tmp_name'];

    $error = $_FILES['imagem']['error'];

Could anyone tell me where the problem is?

    
asked by anonymous 14.04.2015 / 04:25

1 answer

1

You are passing the value of the file to a "common" post in this ajax function. The input file has its own behavior, so it has enctype="multipart/form-data" in the form. Just give a submit normally that the value will be populated in $_FILE and that should work.

    
14.04.2015 / 04:45