title: Failed to open stream: Permission denied when executing fopen after post request
body: <p>I have php code as follows.</p>
  <pre><code>&lt;?php  
    $curl = curl_init();
  
    curl_setopt($curl, CURLOPT_URL, &quot;[HIDDEN]&quot;);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, array(&quot;code&quot; =&gt; &quot;print(1+1)&quot;));
    
    $result = curl_exec($curl);
    echo $result;
  ?&gt;
  </code></pre>
  <p>Whose post request goes to...</p>
  <pre><code> &lt;?php  
     if($_SERVER[&quot;REQUEST_METHOD&quot;] == 'POST') {
       $code = $_POST['code'];
       $handle = fopen(&quot;canvas.py&quot;, &quot;w&quot;);
       fwrite($handle, $code);
       $out = shell_exec(&quot;python canvas.py&quot;);
       echo $out;
     }
   ?&gt;
  </code></pre>
  <p>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.</p>
  <p>I keep getting the error &quot;Failed to open stream: Permission denied&quot; 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.</p>
  <p>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 &quot;php file1.php&quot; in a linux server not owned by me.</p>