【问题标题】:POST data using file_get_contents使用 file_get_contents 发布数据
【发布时间】:2014-12-18 08:03:13
【问题描述】:

我有一个表单,它必须用 JSON 数据中的数据填充,并且应该使用 mpdf 将表单创建为 pdf 并发送到 mail。因为我使用的是 jquery 和 ajax。

首先我使用了将 json 数据发送到 PHP 文件的 ajax。在 PHP 文件中,我使用以下

`$json = file_get_contents('php://input');//to getting json post values we need to use
$obj = json_decode($json,true);
$obj1=http_build_query($obj);
//print_r($obj);
$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $obj1
    )
);

$context  = stream_context_create($opts);

$result = file_get_contents('PDF_Form.php', false, $context);
echo $result;`

现在显示的是结果而不是值。请告诉我问题出在哪里。

我需要将所有的帖子值放在表单中,然后表单应该作为字符串转换为 ajax 响应以创建 pdf 并发送邮件。

问候, 雷卡

【问题讨论】:

    标签: jquery ajax pdf file-get-contents


    【解决方案1】:

    我自己找到了解决这个问题的方法。

    $json = file_get_contents('php://input');//to getting json post values we need to use
    $obj = json_decode($json,true);
    ob_start();
    include('PDF_Form.php');
    $template_html = ob_get_contents();
    ob_end_clean();
    echo $template_html;
    

    在我用过的PDF_Form.php文件中...

    <html>
        <head></head>
        <input type="text" name="eg" value="
            <?php echo $obj['status'];?>
               ">
    
    </html>
    

    完美运行....

    问候,

    雷卡

    【讨论】:

      猜你喜欢
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      • 2012-07-04
      • 1970-01-01
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多