Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Guardar ruta imagen en Mysql

Estas en el tema de Guardar ruta imagen en Mysql en el foro de Mysql en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 29/11/2010, 03:04
 
Fecha de Ingreso: julio-2010
Ubicación: Cerca Sitges (Barcelona)
Mensajes: 98
Antigüedad: 13 años, 9 meses
Puntos: 4
Guardar ruta imagen en Mysql

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
  1. <?php require_once('Connections/contactos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  40.     $tipo_prod = $_POST["lstTipo"];
  41.  
  42. //Guardar imagen
  43.     if(is_uploaded_file($_FILES['fleImagen']['tmp_name'])) { // verifica haya sido cargado el archivo
  44.         $ruta= "/imagenes/".$_FILES['fleImagen']['name'];
  45. @       move_uploaded_file($_FILES['fleImagen']['tmp_name'], $ruta);
  46.     }
  47.    
  48.   $insertSQL = sprintf("INSERT INTO contactos (telefono, foto1, Tipo, Precio, titulo, descripcion) VALUES (%s, %s, %s, %s, %s, %s)",
  49.                        
  50.                        GetSQLValueString($_POST['txttelefono'], "text"),//es correcto anteponer txt ?
  51.                        GetSQLValueString($ruta, "text"),   //ESTE DATO NO ME LO INTRODUCE EN LA BASE DATOS NI EN CARPETA SERVIDOR
  52.                        GetSQLValueString($_POST['lstTipo'], "text"),//es correcto anteponer lst ?
  53.                        GetSQLValueString($_POST['txtPrecio'], "double"),
  54.                        GetSQLValueString($_POST['txttitulo'], "text"),
  55.                        GetSQLValueString($_POST['txtdescripcion'], "text"));
  56.  
  57. mysql_select_db($database_contactos, $contactos);
  58. $Result1 = mysql_query($insertSQL, $contactos) or die(mysql_error());
  59.  
  60.   $insertGoTo = "ingreso_exitoso.php";
  61.   if (isset($_SERVER['QUERY_STRING'])) {
  62.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  63.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  64.   }
  65. @  header(sprintf("Location: %s", $insertGoTo));
  66. }
  67. ?>
  68. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  69. <html xmlns="http://www.w3.org/1999/xhtml">
  70. <head>
  71. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  72. <title>Documento sin t&iacute;tulo</title>
  73. </head>
  74.  
  75. <body>
  76. <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  77.   <table width="590" border="1">
  78.     <tr>
  79.       <td width="208">&nbsp;</td>
  80.       <td width="366">&nbsp;</td>
  81.     </tr>
  82.     <tr>
  83.       <td>&nbsp;</td>
  84.       <td>&nbsp;</td>
  85.     </tr>
  86.     <tr>
  87.       <td>&nbsp;</td>
  88.       <td>&nbsp;</td>
  89.     </tr>
  90.     <tr>
  91.       <td>&nbsp;</td>
  92.       <td>&nbsp;</td>
  93.     </tr>
  94.     <tr>
  95.       <td>&nbsp;</td>
  96.       <td>&nbsp;</td>
  97.     </tr>
  98.     <tr>
  99.       <td>&nbsp;</td>
  100.       <td>&nbsp;</td>
  101.     </tr>
  102.     <tr>
  103.       <td colspan="2" bgcolor="#71AAE5"><div align="center"> <strong><em>Datos de acceso a su/s anuncio/s.</em></strong></div></td>
  104.     </tr>
  105.     <tr>
  106.       <td><strong>Teléfono:</strong></td>
  107.       <td colspan="2"><label for="txttelefono"></label>
  108.         <input type="text" name="txttelefono" id="txttelefono" /></td>
  109.      
  110.     -    </tr>
  111.     <tr>
  112.       <td colspan="2">&nbsp;</td>
  113.     </tr>
  114.    
  115.     <tr>
  116.       <td><strong>foto1:</strong></td>
  117.       <td><label for="flefoto1"></label>
  118.         <input type="file" name="flefoto1" id="flefoto1" /></td>
  119.     </tr>
  120.     <tr>
  121.       <td>&nbsp;</td>
  122.       <td>&nbsp;</td>
  123.     </tr>
  124.     <tr>
  125.       <td>&nbsp;</td>
  126.       <td>&nbsp;</td>
  127.     </tr>
  128.     <tr>
  129.       <td><strong>Nombre:</strong></td>
  130.       <td><label for="txttitulo"></label>
  131.         <input type="text" name="txttitulo" id="txttitulo" /></td>
  132.     </tr>
  133.     <tr>
  134.       <td>&nbsp;</td>
  135.       <td>&nbsp;</td>
  136.     </tr>
  137.     <tr>
  138.       <td><strong>Tipo:</strong></td>
  139.       <td><label for="lstTipo"></label>
  140.         <select name="lstTipo" id="lstTipo">
  141.           <option value="camisetas" selected="selected">Camisetas</option>
  142.           <option value="accesorios">Accesorios</option>
  143.       </select></td>
  144.     </tr>
  145.     <tr>
  146.       <td><strong>Precio:</strong></td>
  147.       <td><label for="txtPrecio"></label>
  148.         <input type="text" name="txtPrecio" id="txtPrecio" /></td>
  149.     </tr>
  150.     <tr>
  151.       <td><strong>Descripci&oacute;n:</strong></td>
  152.       <td><label for="txtdescripcion"></label>
  153.         <textarea name="txtdescripcion" id="txtdescripcion" cols="45" rows="5"></textarea></td>
  154.     </tr>
  155.     <tr>
  156.       <td>&nbsp;</td>
  157.       <td>&nbsp;</td>
  158.     </tr>
  159.   </table>
  160.   <p>
  161.     <input type="submit" name="button" id="button" value="Enviar" />
  162.   </p>
  163.   <input type="hidden" name="MM_insert" value="form1" />
  164. </form>
  165. </body>
  166. </html>
  #2 (permalink)  
Antiguo 29/11/2010, 12:29
Avatar de Snaft_J1  
Fecha de Ingreso: diciembre-2006
Mensajes: 285
Antigüedad: 17 años, 5 meses
Puntos: 8
Respuesta: Guardar ruta imagen en Mysql

holas, yo creo que este post estaria mejor en el foro de php.
pues tu problema no es de bases de datos.
__________________
-= El conocimiento y el saber te hacen un ser libre =-
Ando en busca de conocimiento....

Etiquetas: ruta
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 03:53.