试图输出php - > md5 - > html但该文件为空

时间:2012-04-17 09:58:15

标签: php html md5 invoices

我目前正在使用一个名为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 ---------------------------  */
     }

我感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

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

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 ---------------------------  */
     }

答案 1 :(得分:1)

在“评论意见”之后,问题来自不包含发票HTML的$模板。

结果     $这 - &GT;负载&gt;查看( 'invoice_templates / default_template'); 不包含HTML,但可能只包含状态代码。

我认为你可以朝这个方向寻找。