Ver Mensaje Individual
  #17 (permalink)  
Antiguo 24/09/2008, 17:03
Avatar de hoberwilly
hoberwilly
 
Fecha de Ingreso: julio-2008
Ubicación: Lima - Perú
Mensajes: 769
Antigüedad: 15 años, 9 meses
Puntos: 2
Ya los mas llegamos a la solucion: Update a Imagen guardada en BD

Me falta un poco nada mas, por favor si alguien podria ayudarme:
editarAdmin.php
----------------------
<?php
include('conec.php');
conectarse();
$registro=mysql_query("select * from catalogo where id='".$_GET['id']."'");
$row=mysql_fetch_array($registro);
?>
<html>
<head>
</head>

<body>
<form name="frmimage" method="post" enctype="multipart/form-data" action="actualizarAdmin.php?id=<?php echo $row['id'];?>">
<table>
<tr>
<td><?php echo $row["id"]?></td>
</tr>
<tr>
<td>Nuevo:</td>
<td><input type="file" size="35" id="foto" name="foto" onChange="document.imagen.src='file:///' + this.value">
<br><?php echo "<img src=\"verThumbnail.php?id=".$row['id']."\" name=\"imagen\">"
; ?> //aqui selecciono la nueva imagen a editar (input type="file" id="foto" name="foto") pero ojo con una previsualizacion(onChange="document.imagen.src) a esa imagen(name=imagen)
</td>
</tr>
<tr>
<td>Producto:</td>
<td><input name="producto" type="text" id="producto" size="50" maxlength="45" value="<?php echo $row["producto"]?>"></td>
</tr>
</table>
<center>
<table border=0 cellpadding=15>
<td><input type="submit" name="enviar" id="enviar" value="Guardar"></td>
</table>
</form>
</body>
</html>



<?php
$postback = (isset($_POST["enviar"])) ? true : false;
if($postback){
error_reporting(E_ALL);
include('conec.php');
conectarse();

$mimetypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/png");
$name = $_FILES["foto"]["name"];
$type = $_FILES["foto"]["type"];
$tmp_name = $_FILES["foto"]["tmp_name"];
$size = $_FILES["foto"]["size"];
if(in_array($type, $mimetypes))
{
$fp = fopen($tmp_name, "rb");
$tfoto = fread($fp, filesize($tmp_name));

$tfoto = addslashes($tfoto);
fclose($fp);
@unlink($tmp_name);
$fecha = date("Y-m-d H:i:s");
}
else
{
aqui indicarle que el campo fecha y tfoto (donde esta guardado la primera foto)se deben dejar intacto si es que no es una imagen jpg,png o gif (if(!in_array($type, $mimetypes))
}
$producto=$_POST['producto'];
$sql="update catalogo set foto='$tfoto',producto='$producto',fecha='$fecha' where id='".$_GET['id']."'";
mysql_query($sql) or die( "Error en $sql, error: " . mysql_error() );
header("location: catalogoAdmin1.php");
return;
}
?>