Ya lo conseguí!!!!
subirimagen.php
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="grabarimagen.php" method="post" enctype="multipart/form-data" name="form1">
<p>Imagen a subir:
<input name="foto" type="file">
</p>
<p>
<input name="Submit" type="submit" value="Enviar">
</p>
</form>
</body>
</html>
grabarimagen.php
Código PHP:
<?php
$foto_type = $_FILES['foto']['type'];
$foto_name = $_FILES['foto']['name'];
$foto_size = $_FILES['foto']['size'];
// Compruebas que se ha subido un archivo
if($foto_name != "")
{
$filetype = $foto_type;
// Compruebas que se trata de una foto
if (!strcmp($filetype, "image/gif") || !strcmp($filetype, "image/jpeg") ||
!strcmp($filetype, "image/pjpeg") || !strcmp($filetype, "image/x-png"))
{
$filename = $foto_name;
$filesize = $foto_size;
$file_tmp = $_FILES['foto']['tmp_name'];
//abriendo archivo temporal
$file = fopen($file_tmp, 'rb');
$filedata = fread($file, filesize($file_tmp));
$filedata = addslashes($filedata);
fclose($file);
//Insertando datos
$conexion = mysql_connect('localhost', 'root', '') or die("No se puede conectar");
$db = mysql_select_db('utopia', $conexion) or die("No se puede seleccionar la BD");
mysql_query("INSERT INTO imagenes values('', '$filename', '$filetype', '$filesize', '$filedata')");
}
}
?>
mostrar.php
Código HTML:
<html>
<body>
<table border=1 align="center">
<tr>
<td align="center">Id</td>
<td align="center">Foto</td>
</tr>
Código PHP:
<?php
$conexion = mysql_connect('localhost', 'root', '') or die("No se puede conectar");
$db = mysql_select_db('utopia', $conexion) or die("No se puede seleccionar la BD");
$result = mysql_query("SELECT id from imagenes order by id");
while ($reg = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$reg['id']."</td>";
echo "<td>";
echo "<img src=\"imagen.php?id=".$reg['id']."\">";
echo "</td>";
echo "</tr>";
}
?>
Código HTML:
</table>
</body>
</html>
imagen.php
Código PHP:
<?php
$conexion = mysql_connect('localhost', 'root', '') or die("No se puede conectar");
$db = mysql_select_db('utopia', $conexion) or die("No se puede seleccionar la BD");
$reg = mysql_query("SELECT * FROM imagenes WHERE id = ".$_GET['id']."");
$file = mysql_fetch_array($reg);
header("Content-disposition: ".$file['filename']."");
header("Content-Length: ".strlen($file['filedata'])."");
header("Content-type:".$file['filetype']."");
header("Pragma: no-cache");
header("Expires: 0");
echo $file['filedata'];
?>
Aquí lo dejo por si a alguien le sirve
Saludos!!