Codigo Html:
Código HTML:
<form name="form_productos" enctype="multipart/form-data"> <label>Marca: </label> <input type="text" id="marca" name="marca" value="" /><br /> <label>Modelo: </label> <input type="text" name="modelo" value="" /><br /> <label>Precio: </label> <input type="text" name="precio" value="" /><br /> <label>Cantidad: </label> <input type="text" name="cantidad" value="" /><br /> <label>Imagen: </label> <input type="file" id="imagen" name="imagen" /><br /> <label>Categoria: </label> <select name="categoria"> <option value="elegir">Elegir...</option> <option value="opc1">opcion 1</option> <option value="opc2">opcion 2</option> <option value="opc3">opcion 3</option> </select><br /> <label>Detalle: </label><br /> <textarea name="detalle" cols="40" rows="5" value=""></textarea><br /> <input type="button" value="Enviar" onclick="proceso(this.form);" /> <input type="reset" value="clear" /> </form>
Codigo JavaScript:
Código:
function getXMLHTTPREQUEST()
{
var req;
try{
req=new XMLHttpRequest;
}catch(err1){
try{
req=new ActiveXObject("Msxml2.XMLHTTP");
}catch(err2){
try{
req=new ActiveXObject("Microsoft.XMLHTTP");
}catch (err3){
req=false;
}//try 3
}//try 2
}//try 1
return req;
}
function proceso(form_productos)
{
//instancio objeto xhr
ajax=getXMLHTTPREQUEST();
//obtengo los campos del formulario.-
var vmarca = document.form_productos.marca.value;
var vmodelo = document.form_productos.modelo.value;
var vprecio = document.form_productos.precio.value;
var vcantidad = document.form_productos.cantidad.value;
var vimg = document.form_productos.imagen.value;
var vcategoria = document.form_productos.categoria.value;
var vdetalle = document.form_productos.detalle.value;
//soluciona el problema de cache.-
var ran = parseInt(Math.random() * 99999999);
ajax.open("GET","proceso_adm_productos.php?marca="+vmarca+"&modelo="+vmodelo+"&precio="+vprecio+"&cantidad="+vcantidad+"&imagen="+vimg+"&categoria="+vcategoria+"&detalle="+vdetalle+"&boton=insertar&rand="+ran,true);
ajax.onreadystatechange=function(){
if(ajax.readyState == 4)
{
if(ajax.status == 200)
{
var mensaje = ajax.responseText;
if(mensaje != "ok")
{
alert(mensaje);
}
}//cierra if status.-
}//cierra if readyState.-
};//cierra funcion interna.-
ajax.send(null);
}//cierra funcion proceso().-
Codigo PHP:
Código PHP:
/*
.
.
//codigo de validacion de datos.........
.
.
.
.
*/
//---------- insertar en la db ----------
if($_GET['boton'] == "insertar")
{
//operamos con la IMG.
$direccion="fotos/";
$archivosubido=$direccion.$_FILES[$_POST['imagen']]['name'];
if(strlen($archivosubido)==6)
{
$archivosubido="fotos/ind.gif;
}
move_uploaded_file($_FILES['imagen']['tmp_name'],$archivosubido);
mysql_query("insert into productos(id_categoria,marca,modelo,precio,cantidad,imagen,detalle) values (".$_GET['categoria'].",'".$_GET['marca']."','".$_GET['modelo']."',".$_GET['precio'].",".$_GET['cantidad'].",'".$archivosubido."','".$_GET['detalle']."')")
or die("error al insertar in proceso_adm_productos".mysql_error());
Aclaro: He realizado varias aplicaciones como esta (mover img a carpetas) pero nunca he utilizado ajax como en esta aplicacion, y ahora estoy atacado.

El problema:
No me esta moviendo la imagen a la carpeta fotos/.
La imagen ind.gif es una imagen que ya se encuentra en la carpeta de fotos/ ; esta sirve para aquellos registros que se cargan sin fotografias, entonces es como una foto por defecto que dice "imagen no disponible, disculpe las molestias".

