2016-11-27 3 views
0

Die Seite wird automatisch zu entry.php weitergeleitet, ohne dass die PDF generiert wird. Ich will, dass es das pdf erzeugt und dann weiterleitet. Wenn die Kopfzeile (Location: entry.php); wird entfernt, es erzeugt Pdf. Gibt es einen anderen Weg, es zu erreichen?Fpdf geht in die Kopfzeile Position ohne Pdf zu generieren.

include('connection.php'); 
ob_start(); 
require('fpdf/fpdf.php'); 


if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{ 
    //collect form data 
    $name = $_POST['fname']; 
    $lname = $_POST['lname']; 
    $email = $_POST['email']; 
    $gender=$_POST['dropdown1']; 
    $age=$_POST['age']; 
    $qualification=$_POST['qualification']; 
    $fees=$_POST['fee']; 
    $discount=$_POST['discount']; 
    $tobepaid=$_POST['tobepaid']; 
    $paystatus=$_POST['dropdown2']; 


    $query = "SELECT * FROM details WHERE email = '$email'"; 
$result = mysqli_query($conn, $query) or die (mysqli_error($conn)); 

if (mysqli_num_rows($result) > 0) { 
    session_start(); 
    $_SESSION['registered'] = "Record Already exists."; 
    mysqli_close($conn); 
    header('Location: entry.php'); 
    exit(); 


} 
    else 


$sql = "INSERT INTO details(FirstName, LastName, Email, Sex, Age, Qualification, Fees, Discount, Tobepaid, Paystatus) 
VALUES ('$name', '$lname', '$email', '$gender', '$age', '$qualification', '$fees', '$discount', '$tobepaid', '$paystatus')"; 

$result = mysqli_query($conn, $sql); 


    if(!mysqli_fetch_assoc ($result)) 
{ 
$_SESSION['Msg']= "Submitted Successfully"; 


      class PDF extends FPDF 
{ 
// Page header 
function Header() 
{ 


    // Arial bold 15 
    $this->SetFont('Arial','B',15); 
    // Move to the right 
    $this->Cell(80); 
    // Title 
    $this->Cell(60,10,'Convert HTML TO PDF',1,0,'C'); 
    // Line break 
    $this->Ln(20); 
} 

// Page footer 
function Footer() 
{ 
    // Position at 1.5 cm from bottom 
    $this->SetY(-15); 
    // Arial italic 8 
    $this->SetFont('Arial','I',8); 
    // Page number 
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); 
} 
} 

// Instanciation of inherited class 
$pdf = new PDF(); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 
$pdf->SetFont('Times','',12); 

$pdf->Cell(0,10,'Name : '.$_POST["lname"],0,1); 
$pdf->Cell(0,10,'Email : '.$_POST["email"],0,1); 
$pdf->Cell(0,10,'Mobile : '.$_POST["fname"],0,1); 
$pdf->Cell(0,10,'Comment : '.$_POST["age"],0,1); 

    $pdfname=$_SESSION['UserID']; 


$pdf->Output('Filename.pdf','D'); 

    header("Location: entry.php"); 
} 

else{ 
    $_SESSION['errMsg'] = "Invalid Details"; 
    header("Location: entry.php"); 

} 
+1

Sie müssen die PDF-Datei ausgeben und auf die Festplatte schreiben, bevor Sie zur entry.php wechseln. Auf den ersten Blick sieht es so aus, als ob es nur an den Browser ausgegeben wird. – hayres

Antwort

1

http://fpdf.org/en/doc/output.htm

D: an den Browser senden und einen Dateidownload mit dem namentlich angegebenen Namen erzwingen.

so sollten Sie Ihre arpprach

F zu verwenden sein: mit dem Namen nach Name (kann einen Pfad) gegeben in einer lokalen Datei speichern.