问题
For a small side project, I had to create a call that gets the PDF via WHMCS. I see the API can get the variables, such as quantity, invoice items etc, but I want the same PDF that the system would send if a client had placed an order. I have a PHP app.
UPDATE
Following the awesome advice below, I was able to solve this in one line:
$pdf->Output('invoice.'.$invoicenum.'.pdf', 'F');
Now every time the invoice is viewed, or emailed, the latest version (paid or unpaid) is stored at the location I chose.
回答1:
There is an article Store Pdf Invoice on ftp with this information:
1-Change in this codeINVOICESDIRECTORY
- directory where I'm keeping PDF invoicesADMINDIRECTORY
- administration directory
2- Paste it in last line of invoicepdf.tpl
file in Your template.
if ($status=="Paid") {
if(strpos($_SERVER['PHP_SELF'],"ADMINDIRECTORY") === false) {
if((strpos($_SERVER['PHP_SELF'],"dl.php") !== false) || (strpos($_SERVER['PHP_SELF'],"dl.html") !== false)) {
if(!file_exists("./INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf")) {
$pdf->Output("./INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf", "F");
}
$fullPath = "./INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf";
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".str_replace("-", "/", $path_parts["basename"])."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".str_replace("-", "/", $path_parts["basename"])."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
}
}
else {
if(!file_exists("./../INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf")) {
$pdf->Output("./../INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf", "F");
}
}
}
回答2:
A better solution can be found here. This involves creating an API call that base64 encodes the result to you. Much more sophisticated.
来源:https://stackoverflow.com/questions/19994866/getting-the-pdf-invoice-from-whmcs