zee000
09-13-2011, 05:27 PM
Hello Guys,
i am using php code to file download i want to redirect that page after the download is done or i need to redirect to the next page and download option should appear what should i so for this. really my head got too hot to solve this please suggest me solution as soon as possible .
JShor
09-13-2011, 10:01 PM
Please post a link to the page on your site that contains the problematic script so we can check it out.
zee000
09-14-2011, 01:57 PM
Thanks for reply,
i think its not clear for you what i need , i can`t send my url but i will explain you with a small example here.
<?php
$name = "test.pdf";
$fp =fopen($name, 'rb');
// send headers, dump the pdf file and finally redirect
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=$name");
header("Content-Length: " . filesize($name));
fpassthru($fp);
readfile($fp);
header("refresh: 2; url=test1.html");
?>
after download i need to redirect to another page for that i used some thing like this it worked fine in FF but not working in IE . Can you check this and provide me some solution.
you can't send more headers (your redirect) after you send regular data (your PDF). Your best best would be to have the download open in a new window, and redirect the original window (e.g., the [download] button would open the PDF in a new window, and you could use javascript to detect the click and ask the server for the redirect page).
zee000
09-14-2011, 03:40 PM
Hello thanks for the reply.
I am not much clear how to do this , can you give me some example with explanation.
basically, you can't do this in a single page. once you send output to the browser (yuor pdf file), you can't send more headers (your redirect). so, a possible solution is to do it on two different pages.
If you post your code I might be able to give you an example.
zee000
09-15-2011, 06:26 PM
Ya, my code is already posted here please go through my second post and give me some solution for that.
you only posted a section of php code, which you said was only "an example." please post your actual php code, and the html markup of the referring page as well, so we can determine what the best approach would be.
zee000
09-17-2011, 02:05 PM
okay,
this is my first page after all the form fields are submitted i am creating a pdf using tcpdf
and at the end i am redirecting to the next page as you see below its redirecting in mozilla and its not working in ie .. i think this may give you the clear idea ..:)
require_once('config/lang/eng.php');
require_once('tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
//$image_file = K_PATH_IMAGES.'logo.jpg';
//$this->Image($image_file, 10, 10, 60, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 25);
// Title
$this->Cell(0, 0, 'Trip Invoice', 0, false, 'R', 0, '', 0, false, 'T', 'M');
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
//$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('MY Red Cap');
$pdf->SetTitle('My Trip Invoice');
$pdf->SetSubject('My Trip Invoice');
$pdf->SetKeywords(', PDF, Invoice, trip, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('', '', 10);
// add a page
$pdf->AddPage();
echo $date=date("m/d/y");
require('htmlcolors.php');
// set some text to print
$html = <<<EOD
<table border="1" cellspacing="0" cellpadding="4" bottom="5">
<tr >
<td>$fullname<br />$address,$city <br /> $state<br />$zip<br />$phone</td><td align="right"> Invoice # $id<br />
DATE: $date</td>
</tr>
<tr>
<td width="35">TO</td><td width="604"></td>
</tr>
</table>
<br/>
<br/>
EOD;
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// Print some HTML Cells
$pdf->SetFillColor(255,255,0);
// print a block of text using Write()
//$pdf->WriteHTML($html,$h=0,$txt, $link='', $fill=0, $align='L', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
// ---------------------------------------------------------
$filename=invoice_;
$file_name="$filename". rand().".pdf";
//Close and output PDF document
ob_clean();
$pdf->Output('tripinvoice/'.$file_name, 'D');
$pdf->Output('tripinvoice/'.$file_name, 'F');
// Exit script. So that no useless data is output-ed.
//============================================================+
// END OF FILE
//============================================================+
//-----------------------------END Code For PDF Generation--------------------\\
header("refresh: 3; URL=mytripinvoice.php?type=". $_GET['type']);
zee000
09-22-2011, 03:22 PM
Hello guys ,
I have solved this problem.using iframe , i have taken my complete download code to the new page and i am using iframe to call that download code page where ever it is needed . That`s it solves my problem.
djr33
09-22-2011, 08:00 PM
Your last post says that you solved the problem. Do you have a new question? If it is different, please post a new thread. If it is the same question, post more information.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.