4

对于一个小型项目,我必须创建一个通过 WHMCS 获取 PDF 的调用。我看到 API 可以获取变量,例如数量、发票项目等,但我想要与客户下订单时系统发送的相同 PDF。我有一个 PHP 应用程序。

更新

遵循以下很棒的建议,我能够在一行中解决这个问题:

$pdf->Output('invoice.'.$invoicenum.'.pdf', 'F');

现在,每次查看或通过电子邮件发送发票时,最新版本(付费或未付费)都会存储在我选择的位置。

4

2 回答 2

2

有一篇文章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");
                }
        }
}
于 2013-11-18T08:01:31.790 回答
0

A better solution can be found here. This involves creating an API call that base64 encodes the result to you. Much more sophisticated.

于 2015-06-01T17:34:47.330 回答