Hola a todos.
Llevo tiempo intentando subir la imagen al servidor y guardar la ruta de la misma en BD Mysql.
Me guarda todos los datos correctamente, excepto la imagen, no la sube al servidor y no guarda la ruta en Mysql.
¿Sería posible subir 5 imágenes?
Alguna sugerencia de este código.
¿Tenéis alguno parecido q funcione?
Muchas gracias.
Código PHP:
Ver original<?php require_once('Connections/contactos.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ?
intval($theValue) : "NULL"; break;
case "double":
$theValue = ($theValue != "") ?
doubleval($theValue) : "NULL"; break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); }
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $tipo_prod = $_POST["lstTipo"];
//Guardar imagen
if(is_uploaded_file($_FILES['fleImagen']['tmp_name'])) { // verifica haya sido cargado el archivo $ruta= "/imagenes/".$_FILES['fleImagen']['name'];
}
$insertSQL = sprintf("INSERT INTO contactos (telefono, foto1, Tipo, Precio, titulo, descripcion) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['txttelefono'], "text"),//es correcto anteponer txt ?
GetSQLValueString($ruta, "text"), //ESTE DATO NO ME LO INTRODUCE EN LA BASE DATOS NI EN CARPETA SERVIDOR
GetSQLValueString($_POST['lstTipo'], "text"),//es correcto anteponer lst ?
GetSQLValueString($_POST['txtPrecio'], "double"),
GetSQLValueString($_POST['txttitulo'], "text"),
GetSQLValueString($_POST['txtdescripcion'], "text"));
$insertGoTo = "ingreso_exitoso.php";
if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ?
"&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING'];
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
<table width="590" border="1">
<tr>
<td width="208"> </td>
<td width="366"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#71AAE5"><div align="center"> <strong><em>Datos de acceso a su/s anuncio/s.</em></strong></div></td>
</tr>
<tr>
<td><strong>Teléfono:</strong></td>
<td colspan="2"><label for="txttelefono"></label>
<input type="text" name="txttelefono" id="txttelefono" /></td>
- </tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td><strong>foto1:</strong></td>
<td><label for="flefoto1"></label>
<input type="file" name="flefoto1" id="flefoto1" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Nombre:</strong></td>
<td><label for="txttitulo"></label>
<input type="text" name="txttitulo" id="txttitulo" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Tipo:</strong></td>
<td><label for="lstTipo"></label>
<select name="lstTipo" id="lstTipo">
<option value="camisetas" selected="selected">Camisetas</option>
<option value="accesorios">Accesorios</option>
</select></td>
</tr>
<tr>
<td><strong>Precio:</strong></td>
<td><label for="txtPrecio"></label>
<input type="text" name="txtPrecio" id="txtPrecio" /></td>
</tr>
<tr>
<td><strong>Descripción:</strong></td>
<td><label for="txtdescripcion"></label>
<textarea name="txtdescripcion" id="txtdescripcion" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<p>
<input type="submit" name="button" id="button" value="Enviar" />
</p>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>