Buenos días intento guardar una imagen en un Base de datos mySQL desde un formulario
El problema es el siguiente......
Problema2:
cada vez que se ejecuta el formulario se sube un nuevo archivo y la variable $_FILE[nombre][propiedad] va devolviendo un array....
por ejemplo para hacer referencia a la primera foto que se subio desde el formulario seria:
$_FILE[nombre][propiedad] [0]
tengo 2 dudas....
1. Se puede reiniciar esta variable?
2. En esta variable se almacenaran archivos solo de este formulario o de otros que esten
en mi pagina(si usara el mismo nombre)($_FILE[nombre])?
Problema1(solucionado):
al ejecutar el "subir_imagen.php" el archivo(imagen seleccionada en el input) no esta cargado por lo tanto no se puede mandar nada a la base... ver linea :15 Código subir_imagen.php eso da falsoSolucion:
El archivo hera demasiado grande.....
AYUDA PORFA.....
La Tabla:CREATE TABLE IF NOT EXISTS `IMG_PERFIL` (
`ID` SMALLINT(6) NOT NULL AUTO_INCREMENT,
`ANCHURA` SMALLINT(6) NOT NULL,
`ALTURA` SMALLINT(6) NOT NULL,
`TIPO` CHAR(15) NOT NULL,
`IMAGEN` mediumblob NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
El formulario:<form method="post" action="subir_imagen.php" onsubmit="return validacion(this)">
<label>Elige una fotografia tipo credencial(2MB max):
</label> <div id="frm-campo-image"></div> <input type="hidden" name="MAX_FILE_SIZE" value="2400" /> <input type="file" id="foto" name="foto_perfil_registro[]" required="true"/> <output id="list"></output>
<input class="botton1" type="submit" value="Registrarse"/>
El archivo subir_imagen.php
<?php
$filename = "foto_perfil_registro";
$link = new mysqli('localhost', 'base', '1234', 'tabla');
//echo "<BR>".$_FILES[ $filename]["name"][0]; //nombre del archivo
//echo "<BR>".$_FILES[ $filename]["type"][0]; //tipo
//echo "<BR>".$_FILES[ $filename]["tmp_name"][0]; //nombre del archivo de la imagen temporal
//echo "<BR>".$_FILES[ $filename]["size"][0]; //tamaño
# Comprovamos que se haya subido un fichero
# Cogemos el formato de la imagen
$filetype =$_FILES[$filename]["type"][0];
if ( $filetype== "image/jpeg" || $filetype== "image/pjpeg" || $filetype == "image/gif" || $filetype == "image/bmp" || $filetype == "image/png") {
# Cogemos la anchura y altura de la imagen
echo "<BR>".$info[0]; //anchura
echo "<BR>".$info[1]; //altura
echo "<BR>".$info[2]; //1-GIF, 2-JPG, 3-PNG
echo "<BR>".$info[3]; //cadena de texto para el tag <img
#Obtenemos el contenido del archivo
# Escapa caracteres especiales
# Agregamos la imagen a la base de datos
$result = $link->query("INSERT INTO `IMG_PERFIL` (ANCHURA,ALTURA,TIPO,IMAGEN) VALUES (" . $info[0] . "," . $info[1] . ",'" . $_FILES[$filename]["type"] . "','" . $imagenEscapes . "')", $link);
# Cogemos el identificador con que se ha guardado
# Mostramos ela imagen agregada
//echo "Imagen agregada con el id ".$id."<BR>";
//echo "<img src='imagen_mostrar.php?id=".$id."' width='".$info[0]."' height='".$info[1]."'>";
}
}
?>
Esto es el script para validar y mostrar la imagen .... Esta de mas pero se los paso por si les sirve...
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
//alert('archivo: ' + i);
// Only process image files.
if (!f.type.match('image.*')) {
continue;
} else {
document.getElementById('list').innerHTML = [''].join('');
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
document.getElementById('list').innerHTML = ['<img id="form-foto" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}