无法打开流:post 请求后执行 fopen 时权限被拒绝
我有 php 代码如下。
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "[HIDDEN]");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, array("code" => "print(1+1)"));
$result = curl_exec($curl);
echo $result;
?>
谁的帖子请求发送到...
<?php
if($_SERVER["REQUEST_METHOD"] == 'POST') {
$code = $_POST['code'];
$handle = fopen("canvas.py", "w");
fwrite($handle, $code);
$out = shell_exec("python canvas.py");
echo $out;
}
?>
我的目标是简单地将帖子请求发送到另一个 php 文件,发送帖子后,打开一个文件并将代码写入其中。然后,回显应该为 2 的输出。如果我的行话不正确,抱歉。
由于 fopen(),我不断收到错误“无法打开流:权限被拒绝”。我可以在同一个文件中使用 fopen,但是当第一个文件中的代码触发第二个文件时,我收到此错误。
它们位于同一目录中,我使用 chmod 777 {filename} 设置了每个文件的权限,包括 canvas.py 文件。最后,不确定这是否重要,但我正在不属于我的 Linux 服务器中使用“php file1.php”执行第一个代码。
I have php code as follows.
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "[HIDDEN]");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, array("code" => "print(1+1)"));
$result = curl_exec($curl);
echo $result;
?>
Whose post request goes to...
<?php
if($_SERVER["REQUEST_METHOD"] == 'POST') {
$code = $_POST['code'];
$handle = fopen("canvas.py", "w");
fwrite($handle, $code);
$out = shell_exec("python canvas.py");
echo $out;
}
?>
My goal here is to simply send a post request to another php file, with the post sent, open a file and write that code to it. Then, echo back the output which should be 2. Sorry if my jargon is incorrect.
I keep getting the error "Failed to open stream: Permission denied" because of fopen(). I can use fopen in the same file, but when the code from the first file triggers the second, I get this error.
They are in the same directory, I have set permissions of each file with chmod 777 {filename}, including the canvas.py file. Lastly, not sure if it matters but I am executing the first code with "php file1.php" in a linux server not owned by me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现了,只需更改Web服务器执行文件的权限即可。
Found it out, just had to change the permission of the web server to execute files.