【问题标题】:Receiving PDF form data into PHP将 PDF 表单数据接收到 PHP 中
【发布时间】:2018-03-12 22:58:48
【问题描述】:

所以我在网上搜索了几个小时,我认为这是一个非常简单的答案,但我似乎找不到。

我正在尝试了解 PDF 表单数据提交的工作原理。我的目标是读取从我设置到 PHP 脚本中的 PDF 表单提交的表单数据。我希望我的 PHP 脚本解析表单数据并将其插入我的 SQL 数据库。

我遇到的障碍是如何接收文件以便解析它?

提交的文件的文件名是什么?

我在我的 PDF 表单上设置了提交按钮,我可以将其导出为 FDF、HTML 或 XFDF,但我只是想将数据转换为字符串或以某种方式将内容转换为 PHP,但我没有知道怎么做。

如果我尝试:

$fileFromPDF = file_get_contents('file.txt', true);

我仍然需要文件名,但我不知道从 PDF 表单提交的文件名。如何获取此文件的名称?它甚至是一个文件还是只是一行xml?如果只是一行XML,我该如何接收呢?

如果有人可以为我指明正确的方向,我们将不胜感激。

【问题讨论】:

    标签: php forms pdf fdf xfdf


    【解决方案1】:

    我想我终于找到了答案。我使用了这段代码:

    $post_body = file_get_contents('php://input');

    我能够得到一个字符串。

    如果有人知道更好的方法,我会全力以赴。谢谢!

    【讨论】:

      【解决方案2】:
      function ArrayFromHttpPut() { # assume a simple PUT, like a PDF form submission
        $arrRtn = array();                                   # init result
        $strInp = file_get_contents('php://input');          # PUT data comes in on StdIn, not in GET
      
        $arrInp = explode("\r\n", $strInp, 2);               # break input into array by only the first CrLf
        $strBnd = $arrInp[0];                                # first line of input is content boundary
        $strInp = $arrInp[1];                                # proceed with remainder of input
      
        $arrInp = explode($strBnd, $strInp);                 # break input into array by content boundary
      
        foreach ($arrInp as $idxInp => $strInp) {            # scan input items
          $arrItm = explode("\r\n\r\n", $strInp, 2);         # break each item into array by only the first double-blank line
          $arrItm[0] = trim($arrItm[0]);                     # drop spurious leading and trailing
          $arrItm[1] = trim($arrItm[1]);                     #   blank lines from both parts
      
          $arrItmNam = explode('=', $arrItm[0]);             # break item name away from Content-Disposition wording
          $strItmNam = str_replace('"', '', $arrItmNam[1]);  # get item name without its enclosing double-quotes
          $strItmVal =                      $arrItm   [1] ;  # get item value
      
          $arrRtn[$strItmNam] = $strItmVal;                  # append (item-name => item-value) to output buffer
        }                                                    # done with scanning input items
        return $arrRtn;                                      # pass result back to caller
      } # ArrayFromHttpPut
      

      【讨论】:

      • 这个解决方案是完全独立的。 PDF“提交表单”操作需要是 HTML 格式,而不是 FDF
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多