我正在尝试在我的网页中运行一个python脚本,该脚本会创建我之后使用PHP读取的文本文件。如果我自己创建一个文本文件,那么读取文本文件的PHP脚本就可以正常工作。但是如果我首先尝试运行python脚本(它应该创建文本文件然后读取它),它就不起作用。 这是我的代码。我检查了权限和路径,但这似乎不是问题。
<html>
<body>
<form method="post" enctype="multipart/form-data" action = "abc.php">
<?php
//creates or updates info.txt
shell_exec("/usr/bin/python /xyz/getinfo.py");
$file = fopen("/xyz/info.txt", "r");
//Output a line of the file until the end is reached
while(!feof($file))
{
$f = fgets($file);
echo $f . "<br>";
}
fclose($file);
?>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>