简体   繁体   English

在另一个PHP脚本中使用exec()函数执行一个PHP脚本

[英]Execute a php script using exec() function in another php script

On my website, I'm using a php class called mpdf http://www.mpdf1.com/mpdf/index.php to create a pdf for users to download. 在我的网站上,我使用的是名为mpdf http://www.mpdf1.com/mpdf/index.php的php类,以创建供用户下载的pdf。

It works by using a file_get_contents('list.php') function to get the contents as html, ready to convert into pdf. 它通过使用file_get_contents('list.php')函数以html格式获取内容,以准备将其转换为pdf。

It works really well, but unfortunately with my site it only returns the actual php code, not the resulting html: 它确实运行良好,但不幸的是,在我的网站上,它仅返回实际的php代码,而不返回最终的html:

<?php include 'inc/head.php'?>
<?php include 'inc/header.php'?>
<?php include 'inc/gold_packageinc.php'?>
<?php include 'inc/footer.php'?>

If I could figure out how to use 如果我能弄清楚如何使用

exec('list.php')

before 之前

file_get_contents('list.php')

I'm sure it would work. 我敢肯定它将起作用。 The thing is it seems really hard to do. 问题是似乎真的很难做到。 Apparently you need to reference the php files or something, but I can't do it. 显然,您需要引用php文件或其他内容,但是我做不到。 I've created a fair whack of php-driven sites now, but I don't know what a 'shell' is or anything! 我现在已经创建了很多由php驱动的网站,但是我不知道什么是“ shell”!

If someone could explain how to get exec('list.php') to work, I'd be very grateful! 如果有人可以解释如何使exec('list.php')正常工作,我将不胜感激! Completely open to work arounds. 完全开放工作环境。 Maybe 'output buffering' if someone could explain? 如果有人可以解释,也许是“输出缓冲”?

Do it like this: 像这样做:

$content = include ('list.php');

instead instead of using file_get_contents returning string, use $content; 使用$content;代替使用file_get_contents返回字符串$content; that way the $content will contain the outputted string from list.php 这样, $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"');

You need to given the full path of that file 您需要提供该文件的完整路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM