Ver Mensaje Individual
  #6 (permalink)  
Antiguo 30/08/2010, 14:01
rafaxusirati
 
Fecha de Ingreso: julio-2010
Ubicación: Cerca Sitges (Barcelona)
Mensajes: 98
Antigüedad: 14 años, 7 meses
Puntos: 4
Respuesta: Error código PHP para subir archivo a servidor, y almacenar la ruta a Mysq

o esta segunda opción??,

perdón por mi pesadez, pero soy bastante novato.


Código PHP:
Ver original
  1. <?php require_once('Connections/con_imag.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= "images/$tipo_prod/".$_FILES['fleImagen']['name'];
  45. if( move_uploaded_file($_FILES['fleImagen']['tmp_name'], $ruta)){
  46.  
  47.  $insertSQL = sprintf("INSERT INTO contactos (Referencia, telefono, Imagen, Tipo, Precio, Nombreimg, Descripcion) VALUES (%s, %s, %s, %s, %s, %s, %s)",
  48.                        GetSQLValueString($_POST['txtReferencia'], "int"),
  49.                        GetSQLValueString($_POST['txttelefono'], "text"),
  50.                        GetSQLValueString($ruta, "text"),
  51.                        GetSQLValueString($_POST['lstTipo'], "text"),
  52.                        GetSQLValueString($_POST['txtPrecio'], "double"),
  53.                        GetSQLValueString($_POST['txtNombreimg'], "text"),
  54.                        GetSQLValueString($_POST['txtDescripcion'], "text"));
  55.  
  56.  
  57.  
  58.    }
  59.    
  60.    mysql_select_db($database_con_imag, $con_imag);
  61.   $Result1 = mysql_query($insertSQL, $con_imag) or die(mysql_error());
  62.  
  63.   $insertGoTo = "ingreso_exitoso.php";
  64.   if (isset($_SERVER['QUERY_STRING'])) {
  65.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  66.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  67.   }
  68. @  header(sprintf("Location: %s", $insertGoTo));
  69. }
  70. ?>
  71. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  72. <html xmlns="http://www.w3.org/1999/xhtml">
  73. <head>
  74. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  75. <title>Documento sin t&iacute;tulo</title>
  76. </head>
  77.  
  78. <body>
  79. <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  80.   <table width="590" border="1">
  81.     <tr>
  82.       <td width="208">&nbsp;</td>
  83.       <td width="366">&nbsp;</td>
  84.     </tr>
  85.     <tr>
  86.       <td>&nbsp;</td>
  87.       <td>&nbsp;</td>
  88.     </tr>
  89.     <tr>
  90.       <td>&nbsp;</td>
  91.       <td>&nbsp;</td>
  92.     </tr>
  93.     <tr>
  94.       <td>&nbsp;</td>
  95.       <td>&nbsp;</td>
  96.     </tr>
  97.     <tr>
  98.       <td>&nbsp;</td>
  99.       <td>&nbsp;</td>
  100.     </tr>
  101.     <tr>
  102.       <td>&nbsp;</td>
  103.       <td>&nbsp;</td>
  104.     </tr>
  105.     <tr>
  106.       <td colspan="2" bgcolor="#71AAE5"><div align="center"> <strong><em>Datos de acceso a su/s anuncio/s.</em></strong></div></td>
  107.     </tr>
  108.     <tr>
  109.       <td><strong>Teléfono:</strong></td>
  110.       <td colspan="2"><label for="txttelefono"></label>
  111.         <input type="text" name="txttelefono" id="txttelefono" /></td>
  112.      
  113.     -    </tr>
  114.     <tr>
  115.       <td colspan="2">&nbsp;</td>
  116.     </tr>
  117.     <tr>
  118.       <td width="208"><strong>Referencia:</strong></td>
  119.       <td width="366"><label for="txtReferencia"></label>
  120.         <input name="txtReferencia" type="text" id="txtReferencia" value="ref. 2654112445" readonly="readonly" /></td>
  121.     </tr>
  122.     <tr>
  123.       <td><strong>Imagen:</strong></td>
  124.       <td><label for="fleImagen"></label>
  125.         <input type="file" name="fleImagen" id="fleImagen" /></td>
  126.     </tr>
  127.     <tr>
  128.       <td>&nbsp;</td>
  129.       <td>&nbsp;</td>
  130.     </tr>
  131.     <tr>
  132.       <td>&nbsp;</td>
  133.       <td>&nbsp;</td>
  134.     </tr>
  135.     <tr>
  136.       <td><strong>Nombre:</strong></td>
  137.       <td><label for="txtNombreimg"></label>
  138.         <input type="text" name="txtNombreimg" id="txtNombreimg" /></td>
  139.     </tr>
  140.     <tr>
  141.       <td>&nbsp;</td>
  142.       <td>&nbsp;</td>
  143.     </tr>
  144.     <tr>
  145.       <td><strong>Tipo:</strong></td>
  146.       <td><label for="lstTipo"></label>
  147.         <select name="lstTipo" id="lstTipo">
  148.           <option value="camisetas" selected="selected">Camisetas</option>
  149.           <option value="accesorios">Accesorios</option>
  150.         </select></td>
  151.     </tr>
  152.     <tr>
  153.       <td><strong>Precio:</strong></td>
  154.       <td><label for="txtPrecio"></label>
  155.         <input type="text" name="txtPrecio" id="txtPrecio" /></td>
  156.     </tr>
  157.     <tr>
  158.       <td><strong>Descripci&oacute;n:</strong></td>
  159.       <td><label for="txtDescripcion"></label>
  160.         <textarea name="txtDescripcion" id="txtDescripcion" cols="45" rows="5"></textarea></td>
  161.     </tr>
  162.     <tr>
  163.       <td>&nbsp;</td>
  164.       <td>&nbsp;</td>
  165.     </tr>
  166.   </table>
  167.   <p>
  168.     <input type="submit" name="button" id="button" value="Enviar" />
  169.   </p>
  170.   <input type="hidden" name="MM_insert" value="form1" />
  171. </form>
  172. </body>
  173. </html>