栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何将变量作为stdin从PHP传递到命令行

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何将变量作为stdin从PHP传递到命令行

我不确定您要达到的目标。您可以使用URL php://
stdin阅读stdin。但这是PHP命令行中的stdin,而不是pdftk中的stdin(通过exec)。

但我会给+1

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;}?>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372986.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号