resulta que tengo un formulario para introducir informacion en una base de datos, uno de los campos es imagen, osea que debo introducir la ruta de una imagen ya en algun servidor.
la pregunta es, como puedo hacer para añadirle un boton para seleccionar la imagen en mi disco duro y que me la suba al servidor y me añada la ruta a la base de datos?
el codigo que tengo es este y en color rojo es donde quiero añadir dicha funcion:
Código:
ante todo, gracias por la ayuda reportada<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"> </td> <td><input type="submit" value="Insertar registro"></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> <?php mysql_free_result($Recordset1); ?>
un saludo
INDUMA