0

所以我一直在网上寻找几个小时,我认为这是一个非常简单的答案,但我似乎无法找到它。

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

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

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

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

如果我尝试:

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

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

任何帮助将不胜感激,或者如果有人能指出我正确的方向。

4

2 回答 2

0

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

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

我能够得到一个字符串。

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

于 2017-10-01T19:20:01.453 回答
0
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
于 2019-10-12T03:45:58.423 回答