尝试输出 php -> md5 -> html,但文件为空


Trying to output php -> md5 -> html but the file is empty

我目前正在为我的发票使用一个名为MyClientBase的开源解决方案,一切运行良好。

通常,当我向客户生成发票时,我可以将其作为PDF或电子邮件(或HTML)进行。生成 HTML 发票时,指向它的链接是安全的(只有登录用户才能查看发票),所以我正在尝试制作可公开查看的发票,以生成我们可以在电子邮件中发送的 md5-html。

现在它通过在正确的文件夹中生成一个 md5-html 文件来工作,一切都很棒,除了 html 文件是空的。我已经在文件夹上将CHMOD设置为777,并尝试了几种解决方案,但没有任何效果。相反,它会在同一页面上生成两张发票(重复),并将 html 文件留空。所以我认为一些熟练的php/html-guy可能会弄清楚这一点。

这是我现在使用的代码:

function generate_html() {
$invoice_id = uri_assoc('invoice_id');
$this->load->library('invoices/lib_output');
$this->load->model('invoices/mdl_invoice_history');
$this->mdl_invoice_history->save($invoice_id, $this->session->userdata('user_id'), $this->lang->line('generated_invoice_html'));
$this->lib_output->html($invoice_id, uri_assoc('invoice_template'));
 /*  ------------------ GENERATE MD5-HTML ---------------------------  */
     $file = md5('my_output_path'.$invoice_id).'.html';
     echo "<a href='my_output_path".$file."'>Link to client invoice</a>";
     $f = fopen('my_invoice_path'.$file, 'w');
     $template = $this->load->view('invoice_templates/default_template');
 fwrite($f, $template);true;    
     /*  ------------------ End generate md5 ---------------------------  */
     }

我很感激我能得到的任何帮助!

试试这个,它应该可以工作,它的作用是获取输出,并将其存储在一个变量中,那么这个变量将是该文件的内容,它可能需要一些调整告诉我,如果你有任何错误

function generate_html() {
$invoice_id = uri_assoc('invoice_id');
$this->load->library('invoices/lib_output');
$this->load->model('invoices/mdl_invoice_history');
$this->mdl_invoice_history->save($invoice_id, $this->session->userdata('user_id'), $this->lang->line('generated_invoice_html'));
$this->lib_output->html($invoice_id, uri_assoc('invoice_template'));
 /*  ------------------ GENERATE MD5-HTML ---------------------------  */
     $file = md5('my_output_path'.$invoice_id).'.html';
     echo "<a href='my_output_path".$file."'>Link to client invoice</a>";
     $f = fopen('my_invoice_path'.$file, 'w');
     ob_start(); // start output buffer flow
     $old_content = ob_get_contents();
     ob_clean();
     $this->load->view('invoice_templates/default_template');
     $template = ob_get_contents(); // assign buffer contents to variable
     ob_end_clean(); // end buffer and remove buffer contents
     fwrite($f, $template);true;   
     echo $old_content;
     /*  ------------------ End generate md5 ---------------------------  */
     }

在"评论讨论"之后,问题来自不包含发票 HTML 的$template。

结果 $this->load->view('invoice_templates/default_template');不包含 HTML,但可能只包含状态代码。

我想你可以朝这个方向搜索。