在另一个php脚本中使用exec()函数执行php脚本
问题描述:
在我的网站上,我使用一个名为mpdf http://www.mpdf1.com/mpdf/index.php的php类来创建用于下载的pdf。在另一个php脚本中使用exec()函数执行php脚本
它通过使用file_get_contents('list.php')
函数来获取内容为html,准备转换为pdf。
它的作品真的很好,可惜我的网站它只返回实际的PHP代码,而不是生成的HTML:
<?php include 'inc/head.php'?>
<?php include 'inc/header.php'?>
<?php include 'inc/gold_packageinc.php'?>
<?php include 'inc/footer.php'?>
如果我能想出如何使用前
exec('list.php')
file_get_contents('list.php')
我确定它会工作。事情似乎很难做到。显然你需要引用php文件或其他东西,但我不能这样做。我现在创建了一个由PHP驱动的网站,但我不知道什么是'shell'或什么!
如果有人能解释如何让exec('list.php')工作,我会非常感激!完全开放以解决问题。也许'输出缓冲'如果有人能解释?
答
做这样的:
$content = include ('list.php');
代替,而不是使用file_get_contents
返回字符串,请使用$content;
这样的$content
将包含输出字符串list.php
答
exec('list.php') is wrong,If you need to execute a php file with exec() function,You need to pass the name of file as argument to PHP.exe file
eg:
exec('C:/xampp/bin/PHP.exe "C:/xampp/htdocs/list.php"');
你需要考虑到文件的完整路径