title: move_uploaded_file gives “failed to open stream: Permission denied ” even with 777
body: <p>I get this error with Apache 2.4 and PHP 7 on CentOS.</p>
  
  <p>I have folder structure like this:</p>
  
  <pre><code>var
    -- www
      -- html
        -- upload.php
        -- uploads
        -- images
  </code></pre>
  
  <p>And when I run move_uploaded_file( $tmpDir, '/var/www/html/uploads' ); - everything works flawlessly.</p>
  
  <p>But the error comes when I try to change the destination directory to /var/www/html/images.</p>
  
  <blockquote>
    <p>Warning: move_uploaded_file(/var/www/html/images/test.jpg): failed to open stream:
    Permission denied in /var/www/html/upload.php on line 14</p>
    
    <p>Warning: move_uploaded_file(): Unable to move '/tmp/phps3D2Em' to
    '/var/www/html/images/test.jpg' in /var/www/html/upload.php on line 14</p>
  </blockquote>
  
  <p>Both folders have the same 755 mode and same owner (apache). But somehow it gives me error when I want to upload in images folder.</p>
  
  <p>I ran posix_getuid() from PHP and it gives me ID of the Apache user.</p>
  
  <p>What could be the issue?</p>
  
  <p>Edit:</p>
  
  <p>Results of ls -lh /var/www/html:</p>
  
  <pre><code>-rw-r--r--.  1  root    root  2.6K Mar 10 13:02 upload.php
  drwxr-xr-x.  5  apache  root    23 Mar 12 16:06 images
  drwxr-xr-x.  2  apache  root   88K Mar 13 12:36 uploads
  </code></pre>
  
  <p>Results of httpd -S:</p>
  
  <pre><code>ServerRoot: "/etc/httpd"
  Main DocumentRoot: "/var/www/html"
  Main errorLog: "/etc/httpd/logs/error_log"
  Mutex authdigest-client: using_defaults
  Mutex ssl-stapling: using_defaults
  Mutex proxy: using_defaults
  Mutex authn-socache: using_defaults
  Mutex default: dir="/run/httpd" mechanism=default
  Mutex mpm-accept: using_defaults
  Mutex authdigest-opaque: using_defaults
  Mutex proxy-balancer-shm: using_defaults
  Mutex rewrite-map: using_defaults
  PidFile: "/run/httpd/httpd.pid"
  Define: _RH_HAS_HTTPPROTOCOLOPTIONS
  Define: DUMP_VHOSTS
  Define: DUMP_RUN_CFG
  User: name="apache" id=48
  Group: name="apache" id=48
  </code></pre>
  
  <p>Edit 2:
  I have this script set on /var/www/html/perms.php:</p>
  
  <pre><code>print posix_getuid();
  $dirs = array_filter(glob('*'), 'is_dir');
  foreach( $dirs as $dir ) {
    if ( is_writable($dir) ) print "{$dir} is writable.&lt;br&gt;";
    else print "{$dir} is not writable.";
  }
  </code></pre>
  
  <p>and the output:</p>
  
  <pre><code>48
  images is not writable. Permissions may have to be adjusted.
  uploads is writable.
  </code></pre>