pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <small id='f7NlU'></small><noframes id='f7NlU'>

    <legend id='f7NlU'><style id='f7NlU'><dir id='f7NlU'><q id='f7NlU'></q></dir></style></legend>
  1. <tfoot id='f7NlU'></tfoot>

    1. <i id='f7NlU'><tr id='f7NlU'><dt id='f7NlU'><q id='f7NlU'><span id='f7NlU'><b id='f7NlU'><form id='f7NlU'><ins id='f7NlU'></ins><ul id='f7NlU'></ul><sub id='f7NlU'></sub></form><legend id='f7NlU'></legend><bdo id='f7NlU'><pre id='f7NlU'><center id='f7NlU'></center></pre></bdo></b><th id='f7NlU'></th></span></q></dt></tr></i><div class="esofpk3" id='f7NlU'><tfoot id='f7NlU'></tfoot><dl id='f7NlU'><fieldset id='f7NlU'></fieldset></dl></div>
      • <bdo id='f7NlU'></bdo><ul id='f7NlU'></ul>

    2. 如何將變量作為標準輸入從 PHP 傳遞到命令行

      How to pass variables as stdin into command line from PHP(如何將變量作為標準輸入從 PHP 傳遞到命令行)

      <small id='piePl'></small><noframes id='piePl'>

            <legend id='piePl'><style id='piePl'><dir id='piePl'><q id='piePl'></q></dir></style></legend>

              <tbody id='piePl'></tbody>
              <bdo id='piePl'></bdo><ul id='piePl'></ul>

                <i id='piePl'><tr id='piePl'><dt id='piePl'><q id='piePl'><span id='piePl'><b id='piePl'><form id='piePl'><ins id='piePl'></ins><ul id='piePl'></ul><sub id='piePl'></sub></form><legend id='piePl'></legend><bdo id='piePl'><pre id='piePl'><center id='piePl'></center></pre></bdo></b><th id='piePl'></th></span></q></dt></tr></i><div class="ipdrts7" id='piePl'><tfoot id='piePl'></tfoot><dl id='piePl'><fieldset id='piePl'></fieldset></dl></div>

              1. <tfoot id='piePl'></tfoot>

              2. 本文介紹了如何將變量作為標準輸入從 PHP 傳遞到命令行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試編寫一個 PHP 腳本,該腳本使用 pdftk 應用程序將 XFDF 與PDF 格式并將合并后的 PDF 輸出給用戶.根據 pdftk 文檔,我可以通過 stdin 傳遞表單數據,并將 PDF 輸出到 stdout 流.從命令行使用 pdftk 的正常文件而非流方式是:

                I am trying to write a PHP script that uses the pdftk app to merge an XFDF with a PDF form and output the merged PDF to the user. According to the pdftk documentation, I can pass the form data in via stdin and have the PDF output to the stdout stream. The normal, file-not-stream way to use pdftk from the command line is:

                pdftk blankform.pdf fill_form formdata.xfdf output filledform.pdf
                

                要在命令行上使用流,您需要輸入:

                to use streams on the command line, you'd enter:

                pdftk blankform.pdf fill_form - output -
                

                我有幾個問題:

                1) 我已經讓 pdftk 使用 xfdf 文件(而不是 stdin)通過 stdout 返回輸出,如下所示:

                1) I have gotten pdftk to return output via stdout using an xfdf file (instead of stdin) like so:

                    exec("pdftk blankform.pdf fill_form formdata.xfdf output -", $pdf_output);
                    file_put_contents("filledform.pdf",$pdf_output);
                

                但根據 Adob??e Reader 的說法,它創建的 pdf 已損壞,并且使用文本編輯器快速瀏覽該文件表明,至少,它沒有將行尾設置在應有的位置.我有一個由 pdftk 創建的完全相同的 PDF,它輸出到一個文件,并且 pdf 在文本編輯器中看起來不錯,所以我知道它不是 pdftk 輸出錯誤數據.

                But the pdf that it creates is corrupt, according to Adobe Reader and a quick peek at the file with a text editor shows that, at the very least, it is not setting the line endings where they should be. I have an identical PDF created by pdftk where it output to a file, and the pdf looks fine in the text editor, so I know that it's not pdftk that's outputting bad data.

                2) 我一生都無法弄清楚如何在 PHP 中設置 stdin 流,以便我可以使用該流作為 pdftk 的輸入.從我在 PHP 文檔中讀到的內容來看,stdin 是只讀的,那么任何東西如何進入該流?

                2) I can not for the life of me figure out how to set the stdin stream in PHP so that I can use that stream as my input for pdftk. From what I'm reading on the PHP documentation, stdin is read-only, so how does anything ever get into that stream?

                理想情況下,我想保持這個非常簡單并避免使用 proc_open().我嘗試使用該函數但不是很成功,這可能是我的錯,而不是函數的錯,但實際上我的目標很簡單,我寧愿避免使用我不需要的強大函數.

                Ideally, I would like to keep this really simple and avoid using proc_open(). I attempted to use that function and wasn't very sucessful, which is probably my fault, not the function's, but really my goals are simple enough I'd rather avoid using robust functions I don't need.

                理想情況下,我的代碼如下所示:

                Ideally my code would look something like:

                 $form_data_raw = $_POST;
                 $form_data_xfdf = raw2xfdf($form_data_raw); //some function that turns HTML-form data to XFDF
                
                 $blank_pdf_form = "blankform.pdf";
                
                 header('Content-type: application/pdf');
                 header('Content-Disposition: attachment; filename="output.pdf"');
                
                 passthru("pdftk $blank_pdf_form fill_form $form_data_xfdf output -);
                

                請注意,可以將實際的 xml 字符串放在命令行中,但是我得到了非常不可靠的結果.

                Just a heads up, it is possible to put the actual xml string in the command line, but I've had very unreliable results with this.

                在很多幫助下,我現在明白我真正的問題是如何通過管道將變量傳遞到 PHP 中的命令行執行".顯然 proc_open 是最好的方法,或者至少是最直接的方法.由于我花了很長時間才弄明白這一點,而且我對谷歌的研究表明其他人可能正在苦苦掙扎,我將發布專門解決我的問題的代碼:

                With much help, I now understand that my real question was "how can pipe a variable to a command line execution in PHP". Apparently proc_open is the best way to go, or at least the most straightforward. Since it took me forever to figure this out and since my research on Google suggests others may be struggling, I'll post the code that specifically worked for my problem:

                $blank_pdf_form = "blankform.pdf";
                $cmd = "pdftk $blank_pdf_form fill_form - output -";
                
                $descriptorspec = array(
                   0 => array("pipe", "r"),
                   1 => array("pipe", "w")
                );
                
                $process = proc_open($cmd, $descriptorspec, $pipes);
                
                if (is_resource($process)) {
                
                    //row2xfdf is made-up function that turns HTML-form data to XFDF
                    fwrite($pipes[0], raw2xfdf($_POST));
                    fclose($pipes[0]);
                
                    $pdf_content = stream_get_contents($pipes[1]);
                    fclose($pipes[1]);
                
                    $return_value = proc_close($process);
                
                    header('Content-type: application/pdf');
                    header('Content-Disposition: attachment; filename="output.pdf"');
                    echo $pdf_content;
                }
                

                推薦答案

                我不確定您要實現的目標.您可以使用 URL php://stdin 讀取標準輸入.但這是來自 PHP 命令行的標準輸入,而不是來自 pdftk(通過 exec)的標準輸入.

                I'm not sure about what you're trying to achieve. You can read stdin with the URL php://stdin. But that's the stdin from the PHP command line, not the one from pdftk (through exec).

                但我會給 proc_open()

                <?php
                
                $cmd = sprintf('pdftk %s fill_form %s output -','blank_form.pdf', raw2xfdf($_POST));
                
                $descriptorspec = array(
                   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
                   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
                   2 => null,
                );
                
                $process = proc_open($cmd, $descriptorspec, $pipes);
                
                if (is_resource($process)) {
                    // $pipes now looks like this:
                    // 0 => writeable handle connected to child stdin
                    // 1 => readable handle connected to child stdout
                
                    fwrite($pipes[0], stream_get_contents(STDIN)); // file_get_contents('php://stdin')
                    fclose($pipes[0]);
                
                    $pdf_content = stream_get_contents($pipes[1]);
                    fclose($pipes[1]);
                
                    // It is important that you close any pipes before calling
                    // proc_close in order to avoid a deadlock
                    $return_value = proc_close($process);
                
                
                    header('Content-type: application/pdf');
                    header('Content-Disposition: attachment; filename="output.pdf"');
                    echo $pdf_content;
                }
                ?>
                

                這篇關于如何將變量作為標準輸入從 PHP 傳遞到命令行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                <i id='qavxG'><tr id='qavxG'><dt id='qavxG'><q id='qavxG'><span id='qavxG'><b id='qavxG'><form id='qavxG'><ins id='qavxG'></ins><ul id='qavxG'></ul><sub id='qavxG'></sub></form><legend id='qavxG'></legend><bdo id='qavxG'><pre id='qavxG'><center id='qavxG'></center></pre></bdo></b><th id='qavxG'></th></span></q></dt></tr></i><div class="hthofa2" id='qavxG'><tfoot id='qavxG'></tfoot><dl id='qavxG'><fieldset id='qavxG'></fieldset></dl></div>
                <legend id='qavxG'><style id='qavxG'><dir id='qavxG'><q id='qavxG'></q></dir></style></legend>

                      <tfoot id='qavxG'></tfoot>
                        • <bdo id='qavxG'></bdo><ul id='qavxG'></ul>
                            <tbody id='qavxG'></tbody>

                          <small id='qavxG'></small><noframes id='qavxG'>

                          主站蜘蛛池模板: 汝成内控-行政事业单位内部控制管理服务商 | 聚合甘油__盐城市飞龙油脂有限公司| 耙式干燥机_真空耙式干燥机厂家-无锡鹏茂化工装备有限公司 | 地磅-电子地磅维修-电子吊秤-汽车衡-无人值守系统-公路治超-鹰牌衡器 | Brotu | 关注AI,Web3.0,VR/AR,GPT,元宇宙区块链数字产业 | 家乐事净水器官网-净水器厂家「官方」 | 餐饮小吃技术培训-火锅串串香培训「何小胖培训」_成都点石成金[官网] | 知网论文检测系统入口_论文查重免费查重_中国知网论文查询_学术不端检测系统 | 天津仓储物流-天津电商云仓-天津云仓一件代发-博程云仓官网 | 气动球阀_衬氟蝶阀_调节阀_电动截止阀_上海沃托阀门有限公司 | 全自动贴标机-套标机-工业热风机-不干胶贴标机-上海厚冉机械 | 天津蒸汽/热水锅炉-电锅炉安装维修直销厂家-天津鑫淼暖通设备有限公司 | 哈尔滨治「失眠/抑郁/焦虑症/精神心理」专科医院排行榜-京科脑康免费咨询 一对一诊疗 | 杭州营业执照代办-公司变更价格-许可证办理流程_杭州福道财务管理咨询有限公司 | 继电器模组-IO端子台-plc连接线-省配线模组厂家-世麦德 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 小型气象站_便携式自动气象站_校园气象站-竞道气象设备网 | 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 对辊式破碎机-对辊制砂机-双辊-双齿辊破碎机-巩义市裕顺机械制造有限公司 | 水轮机密封网 | 水轮机密封产品研发生产厂家 | 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 石油/泥浆/不锈钢防腐/砂泵/抽砂泵/砂砾泵/吸砂泵/压滤机泵 - 专业石油环保专用泵厂家 | 工业洗衣机_工业洗涤设备_上海力净工业洗衣机厂家-洗涤设备首页 bkzzy在职研究生网 - 在职研究生招生信息咨询平台 | 昆明网络公司|云南网络公司|昆明网站建设公司|昆明网页设计|云南网站制作|新媒体运营公司|APP开发|小程序研发|尽在昆明奥远科技有限公司 | 长沙中央空调维修,中央空调清洗维保,空气能热水工程,价格,公司就找维小保-湖南维小保环保科技有限公司 | 专业的新乡振动筛厂家-振动筛品质保障-环保振动筛价格—新乡市德科筛分机械有限公司 | 超声波焊接机,振动摩擦焊接机,激光塑料焊接机,超声波焊接模具工装-德召尼克(常州)焊接科技有限公司 | 北京环球北美考试院【官方网站】|北京托福培训班|北京托福培训 | 铝箔袋,铝箔袋厂家,东莞铝箔袋,防静电铝箔袋,防静电屏蔽袋,防静电真空袋,真空袋-东莞铭晋让您的产品与众不同 | 镀锌钢格栅_热镀锌格栅板_钢格栅板_热镀锌钢格板-安平县昊泽丝网制品有限公司 | 质检报告_CE认证_FCC认证_SRRC认证_PSE认证_第三方检测机构-深圳市环测威检测技术有限公司 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 长沙中央空调维修,中央空调清洗维保,空气能热水工程,价格,公司就找维小保-湖南维小保环保科技有限公司 | 济宁工业提升门|济宁电动防火门|济宁快速堆积门-济宁市统一电动门有限公司 | NBA直播_NBA直播免费观看直播在线_NBA直播免费高清无插件在线观看-24直播网 | 心肺复苏模拟人|医学模型|急救护理模型|医学教学模型上海康人医学仪器设备有限公司 | 福尔卡(北京)新型材料技术股份有限公司 | 复合土工膜厂家|hdpe防渗土工膜|复合防渗土工布|玻璃纤维|双向塑料土工格栅-安徽路建新材料有限公司 | 深圳激光打标机_激光打标机_激光焊接机_激光切割机_同体激光打标机-深圳市创想激光科技有限公司 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 |