title: PHP is creating a directory it can't write to
body: <pre><code>if ( !is_writable( $save_path ) ){
      mkdir( $save_path, 0777, true );
  }
  $uploadfile = $save_path . basename($_FILES[$form_field_name]['name']);
  if ( is_writable( $save_path ) ){
      move_uploaded_file($_FILES[$form_field_name]['tmp_name'], $uploadfile)
  }
  </code></pre>
  
  <p>This will create a new dir inside my uploads dir, and if I putty onto the server and do ls -la, the dir has been created with permissions/ownership:</p>
  
  <blockquote>
    <p>drwxr-xr-x apache apache </p>
  </blockquote>
  
  <p>Great. But moving the uploaded file into that new dir fails with:</p>
  
  <blockquote>
    <p>SAFE MODE Restriction in effect. The script whose uid is 0 is not
    allowed to access
    /var/www/vhosts/domain.com/httpdocs/media/uploads/DE
    owned by uid 48</p>
  </blockquote>
  
  <p>Ok, so I get HOW the error is happening - the new folder is created with owner and group set to "apache" (who I guess is user 48), and user "root" can't get to it (user 0 is root, right?). And I guess safe mode is also stopping me creating the dir as 777 and has decided in its infinite wisdom not to do what I asked it to.</p>
  
  <p>But... how is my PHP script creating directories as "apache", and trying to move stuff into them as root? And how can I get round it without taking an axe to safe mode?</p>