title: PHP: Creating files and preserving file permissions
body: <p>I have a simple architecture at the moment which looks a little something like this:</p>
  
  <p><strong>User sends Email > Postfix > Procmail > PHP Script > Write to third party Web App</strong></p>
  
  <p>The third party web app happens to be a CMS (I am using its API to create records).</p>
  
  <p>The problem that I am having is that users are sending Emails to the user of "support", where as the Web Server runs on the user "apache".</p>
  
  <p>Because of this setup, all the attachments are being created with the user of "support" and the group "support", however I need them to actually be created as "apache:apache" (so that the CMS can read and display these attachments in it's templates). </p>
  
  <p>I understand PHP has functions chown and chmod, however when trying to run these commands even from the command line, I am unable to handover ownership of the files to the user "apache".</p>
  
  <p>Is there an easy way for me to preserve file permissions based on the create directory? Is this something I need to change from php.ini? Or perhaps I need to re-think the architecture?</p>
  
  <p>Thanks for the help!</p>