针对一个小的副业项目,我需要创建一个调用来通过WHMCS获取PDF文件。我看到API可以获取变量,如数量、发票项目等,但我想要的是系统在客户下订单时发送的相同PDF文件。我有一个PHP应用程序。
更新
根据下面的建议,我能够用一行代码解决这个问题:
$pdf->Output('invoice.'.$invoicenum.'.pdf', 'F');
现在每次查看或发送账单时,最新版本(付款或未付款)都会存储在我选择的位置。
这里有一篇关于IT技术的文章Store Pdf Invoice on ftp,其中包含以下信息:
1-更改此代码
INVOICESDIRECTORY
- PDF发票存储目录
ADMINDIRECTORY
- 管理目录
2-将其粘贴到您的模板中invoicepdf.tpl
文件的最后一行。
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");
}
}
}