Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/02/2008, 02:21
El-FeNiX
 
Fecha de Ingreso: enero-2008
Mensajes: 381
Antigüedad: 16 años, 3 meses
Puntos: 19
Problemas con imagenes en la base de datos

He hecho un sistema para subir imagenes a la base de datos, y despues de haberlo conseguide resulta que hay errores en las imagenes

pongo un ejemplo

Subi una imagen de muestra de windows

Esi se ve despues de subirla
http://img411.imageshack.us/img411/3441/inviernort6.jpg

Esi es en realidad
http://img411.imageshack.us/img411/8996/inviernoby0.jpg

Este sistema esta hacho dentro de un modulo para php-nuke, pero creo que se entiende bien

Este es un ejemplo del formulario
Código PHP:
function AddImg() {
    
$msj "";
    
$msj $msj."<table width=\"100%\" border=\"0\" cellspacing=\"3\">";
    
$msj $msj."<tr><td nowrap><form method=\"post\" action=\"modules.php?name=Trucos&amp;par=AddingImg\" enctype=\"multipart/form-data\">";
    
$msj $msj."<b>Nombre de la Imagen</b></td><td><input type=\"text\" name=\"title\" size=\"40\" maxlength=\"100\"></td></tr>";
    
$msj $msj."<tr><td nowrap><b>Imagen</b></td><td><input type=\"file\" name=\"imagen\" size=\"40\" maxlength=\"100\"></td></tr>";
    
$msj $msj."<tr><td>&nbsp;</td><td><input type=\"submit\" name=\"submit\" value=\"Agregar\"></td></tr>";
    
$msj $msj."</form></table>";
    
NewTable("A&ntilde;adir Plataforma"$msj"FINISH");

Este es un ejemplo del script que recibe la imagen
Código PHP:
function AddingImg($title$imagen) {
    
// Comprobar si la imagen existe
    
global $db;
    list(
$width$height$type$attr) = getimagesize($_FILES['imagen']['tmp_name']);
    
$check_tittle $db->sql_query("SELECT * FROM tabla WHERE title='$title'");
    if (
sql_num_rows($check_tittle) != 0) {
       
NewTable("Error""La plataforma ya existe""FINISH");
       exit();
    }
    
// Crear variables de la imagen
    
if (is_uploaded_file($_FILES['imagen']['tmp_name']) === TRUE)
    {
        
$imagen file_get_contents($_FILES['imagen']['tmp_name']);
        
$imagen mysql_real_escape_string($imagen);
    } else {
        
NewTable("Error""El archivo de imagen no se subio correctamente""FINISH");
        exit();
    }
    
// Enviar informacion a la base de datos
    
$title addslashes(filter($title"nohtml"1));
    
$type addslashes($type);
    
$attr addslashes($attr);
    
$db->sql_query("INSERT INTO tabla VALUES (NULL,'$title','$imagen','$attr','$type')");
    global 
$dbi;
    
$sql "SELECT `img`, `imgType` FROM tabla WHERE title='$title'";
    
$db_result sql_query($sql$dbi);
    
$img_id mysql_insert_id($dbi);
    
$msj "La nueva plataforma se ha agregado a la base de datos satisfactoriamente"
    
."<br><br>Nombre de la plataforma: $title"
    
."<br><br>Imagen: <img src=modules.php?name=Modulo&amp;par=ShowImg&amp;img_id=$img_id $attr";
    
NewTable("Completado"$msj"FINISH");
}

function 
ShowImg($img_id) {
    if (
$img_id != NULL) {
        global 
$dbi;
        
$sql "SELECT `img`, `imgType` FROM tabla WHERE pid='$img_id'";
        
$db_result sql_query($sql$dbi);
        if (
sql_num_rows($db_result) == 0) { 
            include(
"header.php");
            
$msj "La imagen solicitada no se encuentra en nuestra base de datos!<br><br>";
            
NewTable("Error"$msj._ERROR"FINISH");
            exit(); 
        }
        list(
$img$type) = sql_fetch_row($db_result$dbi);
        if (
$img == NULL) echo("La variable de la imagen es nula");
        if (
$type == NULL) echo("La variable del tipo de imagen es nula");
        
header("content-type: ".image_type_to_mime_type($type));
        echo 
stripslashes($img);
    }

Nose que es lo que esta mal ahi y ademas no me puedo orientar ya que no da ningun error simplemente se cambian algunas lineas de color