将PDF表单数据接收到PHP中 [英] Receiving PDF form data into PHP

查看:146
本文介绍了将PDF表单数据接收到PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I have been looking online for several hours for what I think is a very simple answer but I can't seem to find it.

我试图了解PDF表单数据提交的工作方式.我的目标是读取从我在PHP脚本中设置的PDF表单提交的表单数据.我希望我的PHP脚本能够解析表单数据并将其插入到我的SQL数据库中.

I am trying to understand how PDF form data submitting works. My goal is to read form data submitted from a PDF form that I set up into my PHP script. I want my PHP script to parse the form data and plug it into my SQL database.

我遇到的障碍是如何接收文件以便可以对其进行解析?

The roadblock I am running into is how do I receive the file so I can parse it?

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

What is the filename of the file that gets submitted?

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

I have my submit button setup on my PDF form and I can export it in FDF, HTML, or XFDF, but I am just trying to get the data into a string or get the contents somehow into PHP but I don't know how.

如果我尝试:

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

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

我仍然需要文件名,并且我不知道从PDF表单提交的文件名.如何获得此文件的名称?它甚至是一个文件还是仅一行xml?如果只是一行XML,我怎么收到这个消息?

I still need the name of a file, and I don't know the name of the file that is being submitted from the PDF form. How do I get the name of this file? Is it even a file or just a line of xml? If it is just a line of XML, how do I receive this?

我们将不胜感激,或者如果有人可以向我指出正确的方向,那么

Any help would be appreciated or if someone could point me in the right direction.

推荐答案

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表单数据接收到PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆