页面自动重定向到entry.php而不生成pdf。我希望它生成pdf然后重定向。当标题(Location:entry.php);被删除,它会产生Pdf。有没有其他方法可以实现它?
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");
}
答案 0 :(得分:1)
http://fpdf.org/en/doc/output.htm
D:发送到浏览器并使用名称给出的名称强制下载文件。
所以你的arpprach应该是
F:保存到名称为name的本地文件(可能包含路径)。