<?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('imagenes', $conexion) or die("No se puede seleccionar la BD");
mysql_query("INSERT INTO imagenes values('', '$filename', '$filetype', '$filesize', '$filedata')");
}
}
?>