Ver Mensaje Individual
  #11 (permalink)  
Antiguo 17/03/2008, 15:41
MadKat
 
Fecha de Ingreso: marzo-2008
Mensajes: 171
Antigüedad: 16 años, 2 meses
Puntos: 0
Re: [AYUDA] SUBIR, RELACIONAR Y MOSTRAR IMAGEN - PHP & MySQL

A ver, dejo aca la forma en que estoy haciendo el formulario:

Esta es la pagina que estoy usando para enviar los datos y subir la imagen al directorio que quiero, por ahora todo funciona bien, lo unico que me falta es poder guardar en el campo "imagen" de mi tabla el valor de la ruta donde esta la imagen, ademas me gustaria saber si puedo hacer que verifique que no exista una foto con el mismo nombre y ademas si puedo ponele al nombre de la foto el prefijo del nombre ingresado en el campo "nombre".

Muchas gracias nuevamente, estoy muy agradecido por las respuestas de todos.

Código PHP:
<?php require_once('../Connections/tinymodels.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 modelos (nombre, edad, categoria) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['edad'], "int"),
                       
GetSQLValueString($_POST['categoria'], "text"));

  
mysql_select_db($database_tinymodels$tinymodels);
  
$Result1 mysql_query($insertSQL$tinymodels) or die(mysql_error());
}

mysql_select_db($database_tinymodels$tinymodels);
$query_Recordset1 "SELECT * FROM modelos";
$Recordset1 mysql_query($query_Recordset1$tinymodels) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?><!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&iacute;tulo</title>
</head>

<body>


<p>
  <?php
if(isset($_POST['postback'])){
    
$dirname 'C:\SERVER\www\tiny\modelos\fotos\foto_';
    
    if(!empty(
$_FILES['foto']['name'])){
        if (
is_uploaded_file($_FILES['foto']['tmp_name'])) {
            
move_uploaded_file($_FILES['foto']['tmp_name'],$dirname.$_FILES['foto']['name']);
            
//echo 'La imagen fue correctamente cargada!';
        
} else {
            echo 
'No se pudo cargar la imagen!';
        }
    } else {
        echo 
'Debe especificar la ruta de la imagen';
    }
}

?>
  
</p>
<form action="<?php echo $editFormAction?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  <label>Nombre:
  <input name="nombre" type="text" id="nombre" />
  <br />
  <br />
Edad:
<input name="edad" type="text" id="edad" />
  <br />
  <br />
  Categoria: 
  <select name="categoria" id="categoria">
    <option>Ni&ntilde;os</option>
    <option>Ni&ntilde;as</option>
    <option>Bebes</option>
  </select>
  <br />
  <br />
Imagen:
<input name="foto" type="file" id="foto" />
        <br />
        <br />
  </label>
    <label>
        <input type="submit" name="postback" value="Enviar" />
    </label>
    <input type="hidden" name="MM_insert" value="form1">
</form>


</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>