undefined index file

0

I am sending a form by ajax and I do not want to recognize the input of type file , practically I tried everything.

Note that the submit button is outside the form and then capture the form with the form tag of html that allows you to capture the form no matter where it is.

I followed some rules to capture the input of type file when sending the form to the file php such as if(isset($_FILES['file'])){} , I am also adding the tag to the form entype="multipart/form-data" ,.

All the input captures them except the type file I do not understand why I leave here what I tried

file.html

  <fomr action="info.php" method="post" entype="multipart/form-data" id="form">
       <input type="text" name="nombre" id="nombre" />
       <input type="text" name="apellido" id="apellido" />
       <input type="text" name="correo" id="correo" />
       <input type="file" name="file" id="file" />
   </form>

    <!--luego el boton de submit se encuentra fuera de el fom por x razon-->
    <!--el form es capturado con la etiqueta form de html-->
    <button type="submit" id="send" form="form">ENVIAR</button>

archivo.js

    $("#send").click(function(){

         var form=$("#form");//capturar fomulario
         var nombre=$("#nombre").val();
         var apellido=$("#apellido").val();
         var correo=$("#correo").val();

       form.submit(function(e){

          $.ajax({
                    url: 'ajax/info.php',
                    method: 'post',
                    data: fom.serialize(),
                    type:"JSON",
                    contentType:"application/json; charset=utf-8"

  }).done(function(res){

         console.log(res)

  }).fail(function(){

         console.log(res)

    })

              e.preventDefautl();
            })
        })

info.php

<?php

   $nombre=$_POST["nomre"];
   $apellido=$_POST["apellido"];
   $correo=$_POST["correo"];
   $destino="";
//intente sin if (isset()) tampoco funciono
  if(isset($_FILES["file"])){

      $file=$_FILES["file"]["name"];

       $tmp_name = $_FILES["pictures"]["tmp_name"]
       $destino = "img/" . $_FILES['imagen']['name'];
        move_uploaded_file($tmp_name,$destino);

  }

echo json_encode(array(

                "nombre"=>$nombre,
                "apellido"=>$apellido,
                "correo"=>$correo,
                "file"=>$file
                     ))

?>

error: undefined index file

If I do it without trying to capture the input type file this works perfectly I do not understand what happens I hope and can help me

    
asked by andy gibbs 16.11.2018 в 16:57
source

0 answers