title: File permissions for fopen in write mode - PHP
body: <p>I have a PHP script that writes some rows to a CSV file:</p>
  
  <pre><code>$fp = fopen($csv, 'w');
  </code></pre>
  
  <p>I'm using mode 'w' so that it will create the file if it doesn't exist, however the file is automatically given <strong>644</strong> permissions even though I gave 777 to the whole /var/www/html/ directory (not a good idea but suitable for testing).</p>
  
  <p>How can I write to the file and give it permissions beforehand? Or is there a better way to give write permissions?</p>