douhai5835 2016-08-20 12:55
浏览 61

PHP - 将生成的PDF保存到USER的系统中

I am able to create pdf file using mpdf. Now i want to download that generated file to USER's system just like IDM downloader. But i am unable to do so.

I tried with mpdf options like D,I,F. Only F is working but it save files to server which is not my requirement.

I also tried with which is commented now in code but it didnt work either.

 header('Content-type: application/force-download');
 header('Content-Disposition: attachment; filename=mpdf.pdf');
 readfile('mpdf.pdf');

Here is the code

<?php
    //db connection
    $id = $_REQUEST['id'];

    if($_REQUEST['action'] == "print") {
        mysql_query('SET character_set_results = utf8');
        $result = mysql_query("SELECT question_id FROM *** WHERE exam_id = '$id' ");
        $exam_details = mysql_fetch_assoc(mysql_query("SELECT name, duration, passing_percent, negative_marking  FROM *** WHERE id = '$id' "));
        $num = mysql_num_rows($result);
        while($row = mysql_fetch_assoc($result))
        {
            $results[] = $row['question_id'];
            $question_id = $row['question_id'];
            $result1 = mysql_query("SELECT question, option1, option2, option3, option4 FROM *** WHERE id = '$question_id' ");
            while($row1 = mysql_fetch_assoc($result1))
            {
                $results1[] = $row1;
            }
        }   
    }

    for($i=1; $i<=count($results1); $i++) {
        $question = $i.'. '.$results1[$i-1]['question'];
        $question = str_replace(array("\\","[","]"),"",$question);
        $question = str_replace("(","<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(",$question);
        $option1 = $results1[$i-1]['option1'];
        $option1 = str_replace(array("\\","[","]"),"",$option1);
        $option2 = $results1[$i-1]['option2'];
        $option2 = str_replace(array("\\","[","]"),"",$option2);
        $option3 = $results1[$i-1]['option3'];
        $option3 = str_replace(array("\\","[","]"),"",$option3);
        $option4 = $results1[$i-1]['option4'];
        $option4 = str_replace(array("\\","[","]"),"",$option4);

        $html .= '<p style="font-size: 12pt; font-family: freeserif "><div style="float: left; width: 100%; margin-bottom:5px; font-family: freeserif">'.$question.'</div>';

    }

    include("../mpdf.php");

    $mpdf=new mPDF('');
    $html = mb_convert_encoding($html, 'UTF-8', 'UTF-8');
    $mpdf->SetWatermarkImage('logo.jpg');
    $mpdf->showWatermarkImage = true;
    $mpdf->WriteHTML($html);

    $mpdf->Output('mpdf.pdf');

    //header('Content-type: application/force-download');
    //header('Content-Disposition: attachment; filename=mpdf.pdf');
    //readfile('mpdf.pdf');
?>

So, Please, tell me how to save generated PDF into user's system.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?