Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] $_FILES no coge imagen

Estas en el tema de $_FILES no coge imagen en el foro de PHP en Foros del Web. No entiendo porque no me está cogiendo la variable: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original < div id = "contenedorcambiaravatar" class = "container" style = ...
  #1 (permalink)  
Antiguo 10/09/2016, 05:07
 
Fecha de Ingreso: julio-2015
Ubicación: Barcelona
Mensajes: 93
Antigüedad: 8 años, 8 meses
Puntos: 3
$_FILES no coge imagen

No entiendo porque no me está cogiendo la variable:

Código HTML:
Ver original
  1. <div id="contenedorcambiaravatar" class="container" style="display:none">
  2.             <form id="formcambiaravatar" enctype="multipart/form-data" method="POST">
  3.                 <input type="file" name="imagen" id="imagen">
  4.                 <input class="btn btn-default" type="submit" style="float:left;margin-top:5px;>
  5.                 <i id="loader" class="fa fa-spinner fa-pulse" style="display:none;"></i>
  6.             </form>
  7.         </div>

Código PHP:
Ver original
  1. $submit = $_FILES['imagen'];


Código Javascript:
Ver original
  1. $("#formcambiaravatar").submit(function (e) {
  2.         e.preventDefault();
  3.         $.ajax({
  4.             type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
  5.             url: 'subiravatar', // the url where we want to POST
  6.             data: $('#formcambiaravatar').serialize(), // our data object
  7.             dataType: 'json',
  8.             beforeSend: function () {
  9.                 $("#loader").show();
  10.             }
  11.         }).success(function (data) {
  12.             $("#loader").hide();
  13.  
  14.         });

En cambio si añado ahí en el formulario un input text, sí que me la coge
  #2 (permalink)  
Antiguo 10/09/2016, 05:48
 
Fecha de Ingreso: julio-2015
Ubicación: Barcelona
Mensajes: 93
Antigüedad: 8 años, 8 meses
Puntos: 3
Respuesta: $_FILES no coge imagen

Solucionado poniendo:


new FormData($("#formcambiaravatar")[0] en el data del Ajax.

Etiquetas: formulario, variable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:41.