Ver Mensaje Individual
  #12 (permalink)  
Antiguo 05/04/2007, 05:54
Induma
 
Fecha de Ingreso: enero-2004
Ubicación: en mi casa
Mensajes: 29
Antigüedad: 20 años, 3 meses
Puntos: 1
Re: subir imagen y añadir la ruta a BD

hombre, lo de demonios es una expresion que nada tiene que ver contigo, si no mas bien con la dificultad que para mi representa, no te lo tomes a mal que no es ningun reproche ni nada por el estilo

tengo el upload por un lado, simple y sencillo:
registro.php
Código:
<form enctype="multipart/form-data" action="subearchivo.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="3000000">
archivo: <input name="archivo" type="file"><br>
<input type="submit" value="Subir archivo">
</form>
subearchivo.php
Código:
<?
$directorio = '../images/';

if (move_uploaded_file($_FILES['archivo']['tmp_name'], $directorio . $_FILES['archivo']['name']))
{
    print "El archivo fue subido.";
}
else
{
    print "Error al subir archivo.";
}

?>
hasta aqui vamos bien, el upload funciona

ahora en otro archivo tengo el formulario para subir los datos a la BD:
index.php
Código:
<html>
<head>
<title>Insertar Recetas</title>
<?php require_once('../../Connections/recetas.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  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")) {
  $insertSQL = sprintf("INSERT INTO comida (id, id_categoria, nombre, ingredientes, tiempo, imagen, receta) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['id_categoria'], "int"),
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['ingredientes'], "text"),
                       GetSQLValueString($_POST['tiempo'], "text"),
                       GetSQLValueString($_POST['imagen'], "text"),
                       GetSQLValueString($_POST['receta'], "text"));

  mysql_select_db($database_recetas, $recetas);
  $Result1 = mysql_query($insertSQL, $recetas) or die(mysql_error());

  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_recetas, $recetas);
$query_Recordset1 = "SELECT * FROM comida";
$Recordset1 = mysql_query($query_Recordset1, $recetas) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<style type="text/css">
<!--
.Estilo1 {
	color: #CC0000;
	font-weight: bold;
}
.Estilo2 {font-size: large}
-->
</style>

<div align="center" class="Estilo1 Estilo2">
  <p>INSERTAR RECETAS</p>
</div>

    <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
      <table align="center">
        <tr valign="baseline">
          <td nowrap align="right">Categoria:</td>
          <td><?php
echo '<select name="id_categoria">';
$resul = mysql_query("SELECT * FROM categoria WHERE 1");
while($fila = mysql_fetch_array($resul)){
    echo '<option value="' . $fila['id'] . '">' . $fila['nombre_categoria'] . '</option>';
}
echo '</select>';
?> </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Nombre:</td>
          <td><input type="text" name="nombre" value="" size="36"></td>
        </tr>
        <tr valign="middleline">
          <td nowrap align="right">Ingredientes:</td>
          <td><textarea name="ingredientes" cols="32"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Tiempo:</td>
          <td><input type="text" name="tiempo" value="" size="36"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Imagen:</td>
          <td><input type="text" name="imagen" value="" size="36"></td>
        </tr>
        <tr valign="middleline">
          <td nowrap align="right">Receta:</td>
          <td><textarea name="receta" cols="32"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">&nbsp;</td>
          <td><input type="submit" value="Insertar registro"></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
    </form>
    <p>&nbsp;</p>
    <?php
mysql_free_result($Recordset1);
?>
este tambien funciona bien, me incluye los datos en la BD sin ningun problema

la cuestion es, como unirlo todo y que en el campo de la imagen me recoga la url de la imagen? esa es mi gran duda.

PD: si necesitas la BD dimelo y la pongo tambien por aqui

un saludo

INDUMA