Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/02/2015, 02:25
javier1993
 
Fecha de Ingreso: diciembre-2010
Ubicación: Armenia
Mensajes: 20
Antigüedad: 15 años, 9 meses
Puntos: 0
Pregunta Recuperar Archivos de un campo Blob de SQL

Buenos días, a ver estoy un tanto perdido ya...

Estoy haciendo una web para almacenar los millones de manuales que tienen en el trabajo, los manuales tienen diferentes extensiones,(PDF,.xls,doc...etc...)

bien, ya he hecho la tabla de sql y lo guarda todo bien:(Os enseño captura)



vale a la hora de mostrar los ficheros lo hace bien:


Y los PDF y los txt los abre sin problema:




Pero al abrir un documento Word, excel y demas me descarga un archivo php llamado igual que la pagina y con el contenido de la pagina y parte del contenido del word pero sale todo mal:



el codigo para mostrar las imagenes es este:

Código PHP:
<?php require_once('Connections/local.php'); ?><?php

if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (
PHP_VERSION < 5) {
    
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$maxRows_DetailRS1 = 10;
$pageNum_DetailRS1 = 0;
if (isset(
$_GET['pageNum_DetailRS1'])) {
  
$pageNum_DetailRS1 = $_GET['pageNum_DetailRS1'];
}
$startRow_DetailRS1 = $pageNum_DetailRS1 * $maxRows_DetailRS1;

$colname_DetailRS1 = "-1";
if (isset(
$_GET['recordID'])) {
  
$colname_DetailRS1 = $_GET['recordID'];
}
mysql_select_db($database_local, $local);
$query_DetailRS1 = sprintf("SELECT * FROM archivos  WHERE id = %s", GetSQLValueString($colname_DetailRS1, "int"));
$query_limit_DetailRS1 = sprintf("%s LIMIT %d, %d", $query_DetailRS1, $startRow_DetailRS1, $maxRows_DetailRS1);
$DetailRS1 = mysql_query($query_limit_DetailRS1, $local) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);

if (isset(
$_GET['totalRows_DetailRS1'])) {
  
$totalRows_DetailRS1 = $_GET['totalRows_DetailRS1'];
} else {
  
$all_DetailRS1 = mysql_query($query_DetailRS1);
  
$totalRows_DetailRS1 = mysql_num_rows($all_DetailRS1);
}
$totalPages_DetailRS1 = ceil($totalRows_DetailRS1/$maxRows_DetailRS1)-1;

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">

<title><?php echo $row_DetailRS1['nombre']; ?> en <?php echo $row_DetailRS1['hostname']; ?> </title>
</head>

<body>

<?php 


header
('Content-type: '.$row_DetailRS1['tipo'] );
$contenido = $row_DetailRS1['archivo'];
  

print 
$contenido;

?>
</body>
</html>
<?php
mysql_free_result
($DetailRS1);
?>
Teneis idea de que estoy haciendo mal?

Saludos! Y gracias de antemano!