Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - writing file - Permission denied for one script, but not another in the same directory
    text
    copied!<p>One of my PHP scripts writes data to a file. It is executing without issues. However my test code which calls the same methods in the same way and (for the purpose of trying to clear up this problem) is located in the same directory is reporting a:</p> <pre><code>failed to open stream: Permission denied </code></pre> <p>error.</p> <p>My correctly executing script is simply:</p> <pre><code>try { $printer = new PDFPrinter(); $FDFData = $printer-&gt;assembleFDFData(5); $fdf_file = $printer-&gt;writeFDFFile($FDFData); $printer-&gt;downloadForm($fdf_file); }catch(Exception $e) { echo $e-&gt;getMessage(); } </code></pre> <p>and my test code is:</p> <pre><code> function setUp() { $this-&gt;printer = new PDFPrinter(); $this-&gt;FDFData = $this-&gt;printer-&gt;assembleFDFData(5); } function testWrite() { try { $this-&gt;printer-&gt;writeFDFFile($this-&gt;FDFData); $this-assertTrue(true); } catch(Exception $e) { $this-&gt;assertTrue(false); } } </code></pre> <p>I know the testWrite test code is bad, but I just want to get it to stop throwing that exception first.</p> <p>The script throws the exception when executing the <code>writeFDFFile($this-&gt;FDFData);</code> method as it tries to open the file to write. This is the code which fails:</p> <pre><code>$fp=fopen($fdf_file,'w') </code></pre> <p>I don't understand how 2 files in the same directory with the same permissions can work differently when executing the same code. </p> <p>What could I be doing wrong?</p> <p>Many thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload