hey,
i'm trying to make a pdf, but i get the following error:
1temp/KW1.pdfError!!
as you can see in the code i echo the $factuurnummer, that's the 1 in the error, then i echo the patth it should go to what is temp/wk1.pdf
and then i echo the error.
does anyone know what i'm doing wrong here?
seems like the pdf can't write itself to the temp dir.
this is my code:
<?
require_once("include/phppdflib.class.php");
include_once('connect.php');
$temp = $_GET['id'];
$i = 1;
$query = "SELECT wijnen.naam, orders.aantal, wijnen.prijs6, wijnen.prijs12, wijnen.prijs24 FROM wijnen INNER JOIN orders ON orders.productnr = wijnen.id INNER JOIN orderinfo ON orderinfo.id = orders.ordernr WHERE orderinfo.id = '$temp'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
while(list($naam, $aantal, $prijs6, $prijs12, $prijs24) = mysql_fetch_array($result, MYSQL_NUM))
{
if ($aantal < 12){
${"prodpps".$i} = $prijs6; //prijs per stuk
${"prodpps".$i} = number_format(${"prodpps".$i},2,".","");
${"prodaantal".$i} = $aantal; //aantal per product
${"prodprijs".$i} = $prijs6 * $aantal; //prijs totaal per item
${"prodprijs".$i} = number_format(${"prodprijs".$i},2,".","");
${"prodnaam".$i} = $naam; //prijs van product
}
elseif($aantal < 24){
${"prodpps".$i} = $prijs12; //prijs per stuk
${"prodpps".$i} = number_format(${"prodpps".$i},2,".","");
${"prodaantal".$i} = $aantal; //aantal per product
${"prodprijs".$i} = $prijs12 * $aantal; //prijs totaal per item
${"prodprijs".$i} = number_format(${"prodprijs".$i},2,".","");
${"prodnaam".$i} = $naam; //prijs van product
}
elseif($aantal > 23){
${"prodpps".$i} = $prijs24; //prijs per stuk
${"prodpps".$i} = number_format(${"prodpps".$i},2,".","");
${"prodaantal".$i} = $aantal; //aantal per product
${"prodprijs".$i} = $prijs24 * $aantal; //prijs totaal per item
${"prodprijs".$i} = number_format(${"prodprijs".$i},2,".","");
${"prodnaam".$i} = $naam; //prijs van product
}
${"productenpdf".$i} = "
<tr>
<td>
${'prodnaam'.$i}
</td>
<td align='right'>
${'prodaantal'.$i}
</td>
<td align='right'>
€${'prodpps'.$i}
</td>
<td align='right'>
€${'prodprijs'.$i}
</td>
</tr>
";
$i++;
}
$query3 = "SELECT COUNT(wijnen.naam) FROM wijnen INNER JOIN orders ON orders.productnr = wijnen.id INNER JOIN orderinfo ON orderinfo.id = orders.ordernr WHERE orders.ordernr = '$temp'";
$result3 = mysql_query($query3) or die(mysql_error());
while(list($teller) = mysql_fetch_array($result3, MYSQL_NUM))
{
$AllOrders = "";
for($int=1;$int<=$teller;$int++)
{
$AllOrders .= ${"productenpdf".$int};
}
}
$query2 = "SELECT bedrijf, geslacht, contactpersoon, adres, huisnummer, postcode, plaats, land, email, telefoon, abedrijf, ageslacht, acontactpersoon, aadres, ahuisnummer, apostcode, aplaats, aland, aemail, atelefoon FROM klantgegevens WHERE id = '$temp'";
$result2 = mysql_query($query2) or die('Error : ' . mysql_error());
while(list($bedrijfa, $geslachta, $contactpersoon, $adresa, $huisnummera, $postcode, $plaatsa, $landa, $emaila, $telefoon, $abedrijf, $ageslacht, $acontactpersoon, $aadres, $ahuisnummer, $apostcode, $aplaats, $aland, $aemail, $atelefoon) = mysql_fetch_array($result2, MYSQL_NUM))
{
$bedrijf = $bedrijfa;
$geslacht = $geslachta;
$naam = $contactpersoon;
$adres = $adresa . $huisnummera;
$postcode = $postcode;
$plaats = $plaatsa;
$land = $landa;
$email = $emaila;
$telefoon = $telefoon;
$s_bedrijf = $abedrijf;
$s_naam = $acontactpersoon;
$s_adres = $aadres . $ahuisnummer;
$s_postcode = $apostcode;
$s_plaats = $aplaats;
$s_land = $aland;
$s_telefoon = $atelefoon;
}
$query4 = "SELECT besteldatum, bedrag FROM orderinfo WHERE id = '$temp'";
$result4 = mysql_query($query4) or die('Error : ' . mysql_error());
while(list($besteldatum, $bedrag) = mysql_fetch_array($result4, MYSQL_NUM))
{
$datum = $besteldatum;
$prijs = $bedrag;
}
$datum = date('d-m-Y', strtotime($datum));
$sitenaam = "Kerstens Wijnhandel";
$query5 = "SELECT COUNT(id) FROM orderinfo WHERE betaald = 'ja'";
$result5 = mysql_query($query5) or die('Error : ' . mysql_error());
while(list($tellerfn) = mysql_fetch_array($result5, MYSQL_NUM))
{
$factuurnummer =$tellerfn;
}
echo $factuurnummer;
//gevulde variabelen
$query6 = "UPDATE orderinfo SET factuurnr = $factuurnummer WHERE id = '$temp'";
mysql_query($query6) or die('Error : ' . mysql_error());
// BEGIN VAN HET PDF DOCUMENT
$pdf = new pdffile;
$page = $pdf->new_page("letter");
$in = 0;
$sitenaamfont["height"] = 30;
$sitenaamfont["font"] = "Helvetica";
// Sitenaam
$fh = fopen("../images/logo.jpg", "r");
$filedata = fread($fh, filesize("../images/logo.jpg"));
fclose($fh);
$image = $pdf->jfif_embed($filedata);
$pdf->image_place($image, 600, 0, $page);
// Dikke lijn
$pdf->draw_rectangle(605, 0, 605, 470, $page);
$pdf->draw_rectangle(604, 0, 604, 470, $page);
$pdf->draw_rectangle(603, 0, 603, 470, $page);
// Factuur of Credit-factuur?
$factuurfont["height"] = 20;
$factuurfont["font"] = "Helvetica-Bold";
if ($prijs<0) {
$pdf->draw_text(15, 580, "Credit-Factuur", $page, $factuurfont);
}
else {
$pdf->draw_text(15, 580, "Factuur", $page, $factuurfont);
}
// NAW gegevens
$nawfont["height"] = 12;
$nawfont["font"] = "Times-Roman";
$pdf->draw_text(20, 560, "$bedrijf", $page, $nawfont);
$pdf->draw_text(20, 548, "$naam", $page, $nawfont);
$pdf->draw_text(20, 536, "$adres", $page, $nawfont);
$pdf->draw_text(20, 524, "$postcode $plaats", $page, $nawfont);
$pdf->draw_text(20, 512, $land, $page, $nawfont);
// Factuurnummer
$factnrbold["height"] = 12;
$factnrbold["font"] = "Times-Bold";
$pdf->draw_text(315, 548, "Factuurnummer:", $page, $factnrbold);
$factnrnormal["height"] = 12;
$factnrnormal["font"] = "Times-Roman";
$pdf->draw_text(415, 548, "KW$factuurnummer", $page, $factnrnormal);
// Datum
$datumbold["height"] = 12;
$datumbold["font"] = "Times-Bold";
$pdf->draw_text(363, 500, "Datum:", $page, $datumbold);
$datumnormal["height"] = 12;
$datumnormal["font"] = "Times-Roman";
$pdf->draw_text(410, 500, "$datum", $page, $datumnormal);
// Dikke lijn
$pdf->draw_rectangle(490, 0, 490, 470, $page);
$pdf->draw_rectangle(489, 0, 489, 470, $page);
$pdf->draw_rectangle(488, 0, 488, 470, $page);
// Van alles wat
$vanalleswatbold["height"] = 12;
$vanalleswatbold["font"] = "Times-Bold";
$pdf->draw_text(10, 468, "Artikelnr", $page, $vanalleswatbold);
$pdf->draw_text(80, 468, "Aantal", $page, $vanalleswatbold);
$pdf->draw_text(125, 468, "Omschrijving", $page, $vanalleswatbold);
$pdf->draw_text(420, 468, "Prijs", $page, $vanalleswatbold);
// Artikelen
$in=$in-16;
$artikelen["height"] = 12;
$artikelen["font"] = "Times-Roman";
$totaal = "";
$query = "SELECT wijnen.id, wijnen.naam, orders.aantal, wijnen.prijs6, wijnen.prijs12, wijnen.prijs24 FROM wijnen INNER JOIN orders ON orders.productnr = wijnen.id INNER JOIN orderinfo ON orderinfo.id = orders.ordernr WHERE orderinfo.id = '$temp'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
while(list($id, $naam, $aantal, $prijs6, $prijs12, $prijs24) = mysql_fetch_array($result, MYSQL_NUM))
{
if ($aantal < 12){
${"prodpps".$i} = $prijs6; //prijs per stuk
${"prodpps".$i} = number_format(${"prodpps".$i},2,".","");
${"prodaantal".$i} = $aantal; //aantal per product
${"prodprijs".$i} = $prijs6 * $aantal; //prijs totaal per item
${"prodprijs".$i} = number_format(${"prodprijs".$i},2,".","");
${"prodnaam".$i} = $naam; //prijs van product
}
elseif($aantal < 24){
${"prodpps".$i} = $prijs12; //prijs per stuk
${"prodpps".$i} = number_format(${"prodpps".$i},2,".","");
${"prodaantal".$i} = $aantal; //aantal per product
${"prodprijs".$i} = $prijs12 * $aantal; //prijs totaal per item
${"prodprijs".$i} = number_format(${"prodprijs".$i},2,".","");
${"prodnaam".$i} = $naam; //prijs van product
}
elseif($aantal > 23){
${"prodpps".$i} = $prijs24; //prijs per stuk
${"prodpps".$i} = number_format(${"prodpps".$i},2,".","");
${"prodaantal".$i} = $aantal; //aantal per product
${"prodprijs".$i} = $prijs24 * $aantal; //prijs totaal per item
${"prodprijs".$i} = number_format(${"prodprijs".$i},2,".","");
${"prodnaam".$i} = $naam; //prijs van product
}
$in=$in+16;
$pdf->draw_text(10, 450-$in, "$id", $page, $artikelen);
$pdf->draw_text(80, 450-$in, ${"prodaantal".$i}, $page, $artikelen);
$pdf->draw_text(125, 450-$in, ${"prodnaam".$i}, $page, $artikelen);
$pdf->draw_text(420, 450-$in, "€ ".${"prodprijs".$i}, $page, $artikelen);
$totaal=$totaal+${"prodprijs".$i};
$i++;
}
/// VERZONDEN NAAR:
$pdf->draw_text(20, 115, "Verzonden naar:", $page, $vanalleswatbold);
$pdf->draw_text(20, 103, "$s_bedrijf", $page, $nawfont);
$pdf->draw_text(20, 91, "$s_naam", $page, $nawfont);
$pdf->draw_text(20, 79, "$s_adres", $page, $nawfont);
$pdf->draw_text(20, 67, "$s_postcode $s_plaats", $page, $nawfont);
$pdf->draw_text(20, 55, $land, $page, $nawfont);
// Medium lijn
$pdf->draw_rectangle(115, 390, 115, 470, $page);
$pdf->draw_rectangle(114, 390, 114, 470, $page);
// Woordje "Bedrag (excl btw)" en "BTW"
$bedragbold["height"] = 12;
$bedragbold["font"] = "Times-Bold";
$pdf->draw_text(290, 95, "Bedrag (excl btw)", $page, $vanalleswatbold);
$pdf->draw_text(350, 82, "BTW", $page, $vanalleswatbold);
// Bedrag ex btw en BTW
$btw=$totaal*0.19;
$intotaal=$totaal - $btw;
$totaal=number_format($totaal,2);
$btw=number_format($btw,2);
$intotaal=number_format($intotaal,2);
$bedragnormal["height"] = 12;
$bedragnormal["font"] = "Times-Roman";
$pdf->draw_text(390, 95, "€ $intotaal", $page, $bedragnormal);
$pdf->draw_text(390, 82, "€ $btw", $page, $bedragnormal);
// Medium lijn
$pdf->draw_rectangle(72, 390, 72, 470, $page);
$pdf->draw_rectangle(71, 390, 71, 470, $page);
// Woordje "totaal"
$bedragbold["height"] = 12;
$bedragbold["font"] = "Times-Bold";
$pdf->draw_text(345, 51, "Totaal", $page, $bedragbold);
// Totaal bedrag
$bedragnormal["height"] = 12;
$bedragnormal["font"] = "Times-Roman";
$pdf->draw_text(390, 51, "€ $totaal", $page, $bedragnormal);
// Dikke lijn
$pdf->draw_text(15, 33, "Factuur voldaan", $page, $bedragbold);
$pdf->draw_rectangle(31, 0, 31, 470, $page);
$pdf->draw_rectangle(30, 0, 30, 470, $page);
$pdf->draw_rectangle(29, 0, 29, 470, $page);
// Footer
$footer["height"] = 8;
$footer["font"] = "Helvetica";
$footerbold["height"] = 8;
$footerbold["font"] = "Helvetica-Bold";
$pdf->draw_text(37, -7, "Kerstens Wijnhandel", $page, $footer);
$pdf->draw_text(37, -17, "Sprendlingenpark 25", $page, $footer);
$pdf->draw_text(42, -27, "5061 JT Oisterwijk", $page, $footer);
$pdf->draw_text(210, 15, "ABN AMRO", $page, $footer);
$pdf->draw_text(193, 5, "Rekeningnr 51.56.63.565", $page, $footer);
$pdf->draw_text(177, -5, "IBAN NL 73 ABNA0 515663565", $page, $footer);
$pdf->draw_text(207, -15, "BIC ABNANL2A", $page, $footer);
$pdf->draw_text(193, -35, "BTW-nr. NL111397674B01", $page, $footer);
$pdf->draw_text(179, -45, "KVK Handelsregister 18052581", $page, $footer);
$pdf->draw_text(380, 3, "Tel: +31 13 521 00 13", $page, $footer);
$pdf->draw_text(379, -7, "Fax: +31 13 521 00 14", $page, $footer);
$pdf->draw_text(370, -17, "info@kerstenswijnhandel.nl", $page, $footer);
$pdf->draw_text(352, -27, "http://www.kerstenswijnhandel.nl", $page, $footer);
$output = $pdf->generate();
$myFile = "temp/KW$factuurnummer.pdf";
echo $myFile;
if (file_exists($myFile)) unlink ($myFile);
$fh = fopen($myFile, 'a') or die("Error!!");
fwrite($fh, $output);
fclose($fh);
//header("Content-type: application/pdf");
//echo $output;
echo "<META HTTP-EQUIV='refresh' CONTENT='0; URL=email.php?id=$temp'>";
?>