【问题标题】:Trying to output php -> md5 -> html but the file is empty试图输出 php -> md5 -> html 但文件为空
【发布时间】:2012-04-17 09:58:14
【问题描述】:

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

感谢我能得到的任何帮助!

【问题讨论】:

  • 你能检查一下你使用的不同路径吗?也许,有一个难题:您使用“my_output_path”作为 HREF URL 和 FILE PATH。
  • 所以您的问题与发票、PDF 或 MD5 完全无关,是吗?
  • 另外,是“echo $template”时的发票显示;如果为真,则问题来自文件处理程序或路径。然后检查“fopen”的返回。
  • @Akarun:我检查了好几次。该文件以正确的名称在正确的文件夹中生成,原始发票看起来很棒。只是输出文件是空的。
  • @Alvaro:我明白你的意思,但我很难知道是什么导致了这个问题。问题是关于 md5 生成的发票,我真的没有写任何关于 pdf 的东西。

标签: php html md5 invoices


【解决方案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 ---------------------------  */
     }

【讨论】:

  • 天哪,你解决了。我真的真的真的很感激!非常感谢!
【解决方案2】:

“评论讨论”后,问题出在 $template 中不包含您发票的 HTML。

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

我觉得你可以往这个方向搜索。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-10
    • 2015-01-15
    • 1970-01-01
    • 2018-03-03
    • 2012-07-17
    • 1970-01-01
    • 2011-04-11
    • 1970-01-01
    相关资源
    最近更新 更多