Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/06/2008, 17:47
Avatar de Enishy
Enishy
 
Fecha de Ingreso: septiembre-2007
Mensajes: 121
Antigüedad: 17 años, 6 meses
Puntos: 1
Problema al subir imagen con PostgreSQL

Hola amigos, estoy probando este codigo para subir una imagen al una BD en postgresql, alguien me podria ayudar porfavor a solucionar esto, el error da el siguiente mensaje

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\Apli_MTRS\User\Formularios\Conexion .php:6) in C:\AppServ\www\Apli_MTRS\User\Formularios\ver_arch ivo.php on line 20

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\Apli_MTRS\User\Formularios\Conexion .php:6) in C:\AppServ\www\Apli_MTRS\User\Formularios\ver_arch ivo.php on line 21


inmediatamente despues del mensaje de warning aparecen unos garabatos alogo como esto Áb34r‚ÑC%’Sðáñcs5Áb34r‚ÑC%’Sðáñcs5

el codigo para subir no hay problema pues si aparece en mi tabla pero de todas maneras aqui esta el codigo:

Código PHP:
<?
include("conexion.php");
$mensaje="";
if(isset(
$_POST["enviar"]))
{    
// Obtenemos los datos del archivo subido en el formulario
    
$nombre    $_FILES["archivo"]["name"];
    
$tamano $_FILES["archivo"]["size"];
    
$mime    $_FILES["archivo"]["type"];
    
$arch_tmp$_FILES["archivo"]["tmp_name"];
    

    
// Verificamos que el archivo se haya subido correctamente
    
if( $nombre !="" && $tamano!=)
    {    
// Leemos el archivo que se ha subido en el servidor
        
$fp_archfopen($arch_tmp"rb");
        
$buffer    fread($fp_archfilesize($arch_tmp));
        
fclose($fp_arch);
        
        
// Aqui en adelante es necesario trabajar con transacciones
        // para asegurar la integridad del archivo
        
pg_exec($DB"BEGIN TRANSACTION");
        
//Archivo Max Codigo
        
$query_arch=pg_exec("SELECT Max(codigo_imagen) AS arch FROM imagen") or die ("Error SQL Archivo");
        
$data_arch=pg_fetch_array($query_arch);
        
$max_arch=$data_arch[arch];
        
$maxi_arch=$max_arch+1
        
        
$oid_archivopg_locreate($DB);    // Creamos un OID para nuestro archivo
        
$SQL_insert    "INSERT INTO imagen (codigo_imagen,imagen_nombre, imagen_peso, imagen_tipo, imagen_binario)
                        VALUES('$maxi_arch','$nombre','$tamano', '$mime', $oid_archivo)"
;
        
$RES_insert pg_exec($DB$SQL_insert);

        
$campo_blob    pg_loopen($DB$oid_archivo"w");

        
// Escribimos en el OID el archivo previamente leido en buffer
        
pg_lowrite($campo_blob$buffer);
        
pg_loclose($campo_blob);

        
// Finalizamos nuestra transacción
        
pg_exec($DB"COMMIT TRANSACTION");
        
$mensaje ="El archivo ha sido almacenado exitosamente";
    }
    else
    {    
$mensaje ="No ha subido ningún archivo, intente nuevamente";    }
}
?>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
        <title></title>
        <style media="screen" type="text/css"><!--
td  { font-size: 8pt; font-family: Tahoma }
input { font-size: 8pt; font-family: Tahoma }
--></style>
    </head>

    <body bgcolor="#ffffff">
        <form name="subir_arch" action='<?=$_SERVER["PHP_SELF"];?>' method="post" enctype="multipart/form-data">
        <table border="0" cellpadding="2" cellspacing="2" width="520">
                <tr>
                    <td colspan="2"><b>Subir archivo a la base de datos PostgreSQL</b><hr></td>
                </tr>
                <tr>
                <td colspan="2"><b><font color="red"><?=$mensaje;?></font></b></td>
            </tr>
            <tr>
                <td>Seleccionar archivo</td>
                <td><input type="file" name="archivo" size="50"></td>
            </tr>
                
                <tr>
                <td></td>
                <td><input type="submit" name="enviar" value="Guardar archivo"><input type="hidden" name="MAX_FILE_SIZE" value="32000"></td>
            </tr>
        </table>
        </form>
        <hr>
        <table border="0" cellpadding="2" cellspacing="1" bgcolor="#dcdcdc">
            <tr>
                <td colspan="8" bgcolor="#a9a9a9">
                    <div align="center">
                        <b>LISTADO DE DOCUMENTOS ACTUALMENTE ALMACENADOS EN LA TABLA</b></div>
                </td>
            </tr>
            <tr>
                <td><b>ID</b></td>
                <td><b>Nombre archivo</b></td>
                <td><b>Tama&ntilde;o</b></td>
                <td><b>Tipo MIME</b></td>
                <td><b>OID</b></td>
                <td colspan="2"><b>Opciones</b></td>
            </tr>
<?    $SQL_archivos "SELECT * FROM imagen ORDER BY codigo_imagen";
    
$RES_archivos pg_exec($DB$SQL_archivos);
    
$contador 0;
    while (
$fila pg_fetch_object ($RES_archivos))
    {  
?>            <tr bgcolor="white">
                <td><?=$fila->codigo_imagen;?></td>
                <td><?=$fila->imagen_nombre;?></a></td>
                <td><?=$fila->imagen_peso;?></td>
                <td><?=$fila->imagen_tipo;?></td>
                <td><?=$fila->imagen_binario;?></td>
                <td width="35"><a href="ver_archivo.php?id=<?=$fila->codigo_imagen;?>&opc=v" target="_blank">Ver</a></td>
                <!-- <td><a href="ver_archivo.php?id=<?=$fila->id_archivo;?>&opc=d">Descargar</a></td> -->
            </tr>
<?    }    ?>
        </table>
    </body>

</html>
y el codigo el cual surge el error es esto el de ver y aqui esta:

Código PHP:
<?
include("conexion.php");

$id $HTTP_GET_VARS["id"];
$opc$HTTP_GET_VARS["opc"];
$SQL_buscar    "SELECT * FROM imagen WHERE codigo_imagen=$id";
$RES_buscar    pg_exec($DB$SQL_buscar);
if( 
pg_numrows($RES_buscar) > )
{    
$ROW_buscar pg_fetch_object($RES_buscar);

    
$nombre        $ROW_buscar->imagen_nombre;
    
$tamano        $ROW_buscar->imagen_peso;
    
$tipo_mime    $ROW_buscar->imagen_tipo;
    
$archivo_oid$ROW_buscar->imagen_binario;

    
pg_exec($DB"BEGIN TRANSACTION");
    
$campo_blob    pg_loopen($DB$archivo_oid"r");
    if (
$opc=="v")
    {    
// Creamos las cabeceras para ver el archivo
        
header("Content-type: $tipo_mime");
        
header("Pragma: no-cache");
    }
    
/*if ($opc=="d")
    {    // Creamos las cabeceras para descargar el archivo
        header("Content-type: $tipo_mime");
        header("Content-Disposition: attachment; filename=$nombre");
        header("Content-length: $tamano");
        header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
        header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
        header("Cache-Control: no-cache, must-revalidate");
        header("Pragma: no-cache");
    }*/

    
pg_loreadall($campo_blob);

    
pg_loclose($campo_blob);
    
pg_exec($DB"COMMIT TRANSACTION");

}
?>