title: Unable to upload file from PHP to Centos server?
body: <p>I am having trouble uploading a file from PHP to Centos 7.0 Apache Server</p>
  
  <p>PHP CODE</p>
  
  <pre><code>  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Upload your files&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form enctype="multipart/form-data" action="index.php" method="POST"&gt;
      &lt;p&gt;Upload your file&lt;/p&gt;
      &lt;input type="file" name="uploaded_file"&gt;&lt;/input&gt;&lt;br /&gt;
      &lt;input type="submit" value="Upload"&gt;&lt;/input&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?PHP
    if(!empty($_FILES['uploaded_file']))
    {
      $path = "/var/www/html/";
      $path = $path . basename( $_FILES['uploaded_file']['name']);
      if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
        echo "The file ".  basename( $_FILES['uploaded_file']['name']). 
        " has been uploaded";
      } else{
          echo "There was an error uploading the file, please try again!";
      }
    }
  ?&gt;
  </code></pre>
  
  <p>Please note that file_uploads is on in php.ini</p>
  
  <p>and the folder "/var/www/html/" has permission 0777 and the owner of it is apache </p>
  
  <p>I tried almost all solutions in stackoverflow, </p>
  
  <pre><code>chmod -R 0777 /var/www/html
  
  chown apache /var/www/html
  
  find /var/www/html/ -type f -print0 | xargs -0 chmod -v 777 
  </code></pre>
  
  <p>Still file upload fails, and got this error in HTTPD error_log</p>
  
  <pre><code>[Tue Mar 19 10:34:21.257969 2019] [:error] [pid 27446] [client 172.20.20.41:61798] PHP Warning:  move_uploaded_file(/var/www/html/Scan.pdf): failed to open stream: Permission denied in /var/www/html/index.php on line 23, referer: http://10.104.25.70/index.php
  [Tue Mar 19 10:34:21.258095 2019] [:error] [pid 27446] [client 172.20.20.41:61798] PHP Warning:  move_uploaded_file(): Unable to move '/tmp/php64POiK' to '/var/www/html/Scan.pdf' in /var/www/html/index.php on line 23, referer: http://10.104.25.70/index.php
  </code></pre>
  
  <p>the output of </p>
  
  <pre><code>ls -l 
  </code></pre>
  
  <p>is</p>
  
  <pre><code>drwxrwxrwx. 3 apache root 34 Mar 18 13:24 html
  </code></pre>
  
  <p>the output of</p>
  
  <pre><code>stat html
  </code></pre>
  
  <p>is</p>
  
  <pre><code>  File: ‘html’
    Size: 34              Blocks: 0          IO Block: 4096   directory
  Device: fd00h/64768d    Inode: 67281951    Links: 3
  Access: (0777/drwxrwxrwx)  Uid: (   48/  apache)   Gid: (    0/    root)
  Context: system_u:object_r:httpd_sys_content_t:s0
  Access: 2019-03-19 09:09:19.056277906 +0300
  Modify: 2019-03-18 13:24:45.504174727 +0300
  Change: 2019-03-19 10:37:18.901089085 +0300
   Birth: -
  </code></pre>