dongyu1979 2012-04-17 09:58
浏览 34
已采纳

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

I'm currently using a open source solution for my invoices called MyClientBase and everything is working really well.

Normally when I generate an invoice to a client, I can either do it as a PDF or e-mail (or HTML). When generating the HTML-invoice the link to it is secure (only logged in users can view the invoice) so I'm trying to make publicly viewable invoices that generates a md5-html that we can send in the e-mails.

Right now it's working by generating a md5-html file in the right folder and everything is great, except that the html-file is empty. I've set the CHMOD to 777 on the folder and tried several solutions but nothing really works. Instead it generates two invoices (duplicates) on the same page and leaves the html-file empty. So I think some skilled php/html-guy might figure this one out.

Here's the code I'm using right now:

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

I appreciate any help I can get!

  • 写回答

2条回答 默认 最新

  • doupang3062 2012-04-17 10:38
    关注

    try this, it should work, what it does is it fetches the output, and store it in a variable then this variable will be the content of that file it might need some tweaks tell me if you get any errors

    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条)

报告相同问题?

悬赏问题

  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题