title: Can't upload files using the move_uploaded_file in PHP on Godaddy shared hosting
body: <p>I have a form on one of my pages (edit_post.php) where I'm trying to upload files to a folder on my server using PHP's move_uploaded_file(). On my local machine, it actually works fine but on Godaddy shared hosting it doesn't work. Here is the relevant PHP code:</p>
  <pre><code>&lt;?php
  include(&quot;../../config/config.php&quot;);
  include(&quot;../classes/User.php&quot;);
  include(&quot;../classes/Post.php&quot;);
  
  
  /**
   * Get an instance of the Post class
   * */
  $posts = new Post($con, $_REQUEST['userLoggedIn']);
  
  
  if ( isset($_POST['update_post'])) {
  
    $post_id = $_POST['post_id'];
    
    /**
     * If the user doesn't change the header image for the post 
     * then just send the filename/directory of the current image.
     * */
    $unchangedFileName = $_POST['headerImage'];
  
    /**
     * If the user doesn't change to post header image this 
     * part of the code will NOT be ran
     */
    if (isset($_FILES['file']['name'])) {
  
      $uploadOk = 1;
      $imagePath = $_FILES['file']['name'];
      $errorMessage = &quot;&quot;;
  
      if ($imagePath != &quot;&quot;) {
  
       $targetDir = &quot;assets/img/posts/&quot;;
  
        // Image Variable for moving the file to the correct folder
        $imagePath = $targetDir . uniqid() . basename($imagePath); 
        $imageFileType = pathinfo($imagePath, PATHINFO_EXTENSION);
  
  
        if ($_FILES['file']['size'] &gt; 10000000) {
          $errorMessage = &quot;Sorry your file is too large. The File Limit is 1MB&quot;;
          $uploadOk = 0;
        }
  
        if (strtolower($imageFileType) != &quot;jpeg&quot; &amp;&amp; strtolower($imageFileType) != &quot;png&quot; &amp;&amp; strtolower($imageFileType) != &quot;jpg&quot;) {
          $errorMessage = &quot;Sorry, only jpeg, jpg and png files are allowed&quot;;
          $uploadOk = 0;
        }
  
        if ($uploadOk) {
          if (move_uploaded_file($_FILES['file']['tmp_name'], $imagePath )) {
            echo 'image uploaded okay';
          } else {
            echo &quot;image did not upload&quot; . &quot;&lt;br&gt;&quot;;
            echo &quot;$imagePath&quot; . &quot;&lt;br&gt;&quot;;
            $uploadOk = 0;
          }
        }
      }
  
      if ($uploadOk) {
      /**
       * Send to Post.php class 
       * 
       * */
        $posts-&gt;editPost($_REQUEST, $imagePath);
      } else {
        echo &quot;$errorMessage&quot;;
      }
  
    } else {
  
      /**
       * If no changes were made to the header image this $unchangedFileName
       * will be the image variable that will be sent to the Post.php class
       *  */ 
      $posts-&gt;editPost($_REQUEST, $unchangedFileName);
    }
  
  
    
  
  }
  </code></pre>
  <p>Oddly enough on another page (create-post), I have some code that is similar, the difference between these pages is that the above is for editing the contents of a post while the code below is for creating a post. The code below works just fine moves the file to the correct destination. Both uses the move_uploaded_file() function and both are set to the same directory <code>assets/img/posts/</code>.</p>
  <p>Also with the (edit_post) page, the updates are done asynchronously with no page reload, with the code below (create-post) is not, it will automatically redirect to another page if the post is successfully created whether this part makes a difference or not I don't know.</p>
  <pre><code>if (isset($_POST['post'])) {
   
      $uploadOk = 1;
      $imageName = $_FILES['inpFile']['name'];
      $errorMessage = &quot;&quot;;
   
      if ($imageName != &quot;&quot;) {
          $targetDir = &quot;assets/img/posts/&quot;;
          $imageName = $targetDir . uniqid() . basename($imageName);
          $imageFileType = pathinfo($imageName, PATHINFO_EXTENSION);
   
          if ($_FILES['inpFile']['size'] &gt; 10000000) {
              $errorMessage = &quot;Sorry your file is too large&quot;;
              $uploadOk = 0;
          }
   
          if (strtolower($imageFileType) != &quot;jpeg&quot; &amp;&amp; strtolower($imageFileType) != &quot;png&quot; &amp;&amp; strtolower($imageFileType) != &quot;jpg&quot;) {
              $errorMessage = &quot;Sorry, only jpeg, jpg and png files are allowed&quot;;
              $uploadOk = 0;
          }
   
          if ($uploadOk) {
              if (move_uploaded_file($_FILES['inpFile']['tmp_name'], $imageName)) {
                  //image uploaded okay
              } else {
                  //image did not upload
                  $uploadOk = 0;
              }
          }
      }
   
      if ($uploadOk) {
          $post = new Post($con, $userLoggedIn);
          $post-&gt;submitPost($_POST['post_text'], 'none', $imageName, $_POST['post_heading']);
          header(&quot;Location: index.php&quot;);
      } else {
          echo &quot;&lt;div style='text-align:center;' class='alert alert-danger'&gt;
                  $errorMessage
              &lt;/div&gt;&quot;;
      }
  }
   
  ?&gt;
  </code></pre>
  <p>I don't think it is a folder permission issue if it was then neither page would work correctly. But I'm hard press to figure out what else I can do. Also looking at my Filemanager on Godaddy the permissions on that directory are set to 0755, and my PHP version
  on Godaddy is 7.2. I don't know if any of this makes a difference or not, but I figured I would include it anyway. I also tried an absolute path but that also did not work.</p>