Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/11/2012, 04:49
Avatar de davincci
davincci
 
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 21 años, 8 meses
Puntos: 0
Guardar en Mysql pdf

Hola a todos.

Estoy generando pdf con FPDF, hasta el momento todo anda bien, pero lo que no he podido es como guardar el pdf generado en una tabla en Mysql, he realizado lo siguiente y no se donde esta el error.

Esta es la tabla
Código PHP:
CREATE TABLE `pdfs` (
  `
Id` int(11) NOT NULL auto_increment,
  `
File` blob NOT NULL,
  
PRIMARY KEY  (`Id`)
) 
ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; 
y este el php

Código PHP:
<?php require_once('../../../../../Connections/conex.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  
$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;
}
}

mysql_select_db($database_conex, $conex);
$query_GuardarPdf = "SELECT * FROM pdfs";
$GuardarPdf = mysql_query($query_GuardarPdf, $conex) or die(mysql_error());
$row_GuardarPdf = mysql_fetch_assoc($GuardarPdf);
$totalRows_GuardarPdf = mysql_num_rows($GuardarPdf);
/* incluimos primeramente el archivo que contiene la clase fpdf */
include ('fpdf/fpdf.php');


/* tenemos que generar una instancia de la clase */
        
$pdf = new FPDF();
        
$pdf->AddPage();

/* seleccionamos el tipo, estilo y tamaño de la letra a utilizar */
        
$pdf->Image('Logo2.jpg' , 120 ,44, 77 , 40,'JPG', 'http://localhost/Guia/pdf/Logo2.jpg');
        
$pdf->SetFont('Helvetica', 'B', 10);
        
$pdf->Write (7,"                         PRUEBAS DE GUIAS");
        
$pdf->Ln();
        
$pdf->Ln();
        
$pdf->Write (7,"Número de guía:         ");$pdf->Cell(55,7,$_POST['guia'],1,0,'C');
        
$pdf->Ln();
        
$pdf->Ln();
        
$pdf->Write(7,"Fecha de envio:          ");$pdf->Cell(55,7,$_POST['Fenvio'],1,5,'C');                                  
        
$pdf->Ln();
        
$pdf->Write (7,"Responsable:               ");$pdf->Cell(55,7,$_POST['remite'],1,0,'C');
        
$pdf->Ln();
        
$pdf->Ln();
        
$pdf->Write (7,"Remite:                        ");$pdf->Cell(55,7,$_POST['RemiteCiudad'],1,0,'C');
        
$pdf->Ln();
        
$pdf->Ln();
        
$pdf->Write (7,"Ciudad remitente:       ");$pdf->Cell(55,7,$_POST['CiudadRemitente'],1,0,'C');
        
$pdf->Ln();
        
$pdf->Ln();
        
$pdf->Write (7,"Destinatario:                ");$pdf->Cell(55,7,$_POST['Destina'],1,0,'C');
        
$pdf->Ln();
        
$pdf->Ln();
        
$pdf->Write (7,"Tipo de envio:              ");$pdf->Cell(55,7,$_POST['TipoEnvio'],1,0,'C');
        
$pdf->Ln();
        
$pdf->Ln();
        
$pdf->Write (7,"Tipo de transporte:     ");$pdf->Cell(55,7,$_POST['Transporte'],1,0,'C');
        
$pdf->Ln();
        
$pdf->Ln();
        
$pdf->Write (7,"Observaciones:          ");$pdf->Cell(55,7,$_POST['Observacion'],1,0,'C');
        
$pdf->Ln();
        
$pdf->Ln();        
        
$pdf->Ln();
        
$pdf->Ln(); //salto de linea
        
$pdf->Ln(); //salto de linea
        
$pdf->SetTextColor('255','0','0');//para imprimir en rojo
        
$rand = $_POST['guia'];
        
$doc=$pdf->Output("Guia$rand.pdf",'F');
        
$sql = "INSERT INTO pdfs ('File') VALUES ('$doc' )";
        echo 
"<script language='javascript'>window.open('Guia$rand.pdf','_self','');</script>";//para ver el archivo pdf generado
        
exit;
mysql_free_result($GuardarPdf);
?>
__________________
Mil gracias por sus enseñanzas.

Davincci