title: How to fix mkdir() "Read-only file system" on shared hosting?
body: <p>I'm trying to set up functionality which allows a user to upload files to a directory on a server (shared hosting). The user can type in an upload folder name and select files. If the folder doesn't exist, it gets created.</p>
  
  <p>Please note that this is no big upload system, but for only one user.</p>
  
  <p>My code works fine on <code>localhost</code>. 
  With the public server (shared hosting), creating the folder works. But no files show up in it.</p>
  
  <p><strong>Upload function, <code>process.php</code>:</strong></p>
  
  <pre><code>// run code only if post request went through
  if ($_SERVER['REQUEST_METHOD'] === 'POST' ) {
  
      if (isset($_POST['folder'])) {
          $folder = $_POST['folder'];
      } else {
          $folder = 'new-folder';
      }
  
      // ensure that there are files inside the array to actually upload
      if (isset($_FILES['files'])) {
  
          $errors = [];
          $path = '/dir/data/uploads/images/' . $folder . "/";
  
          // if folder does not exist, create it
          if (!file_exists($path)) {
              mkdir($path, 0777, true);
          } else {
              //stuff
          }
  
          $all_files = count($_FILES['files']['tmp_name']);
  
          for ($i = 0; $i &lt; $all_files; $i++) {
              $file_name = $_FILES['files']['name'][$i];
              $file_tmp = $_FILES['files']['tmp_name'][$i];
              $file_type = $_FILES['files']['type'][$i];
              $file_size = $_FILES['files']['size'][$i];
              $tmp = explode('.', $_FILES['files']['name'][$i]);
              $file_ext = strtolower(end($tmp));
  
              $file = $path . $file_name;
  
              // here follow multiple verifications on the file name, type, size, etc...
              // removed to keep code shorter
  
              if (empty($errors)) {
                  move_uploaded_file($file_tmp, $file);
              }
          }
  
          if ($errors) print_r($errors);
      } 
  }
  </code></pre>
  
  <p><strong>Attempts and observations:</strong></p>
  
  <ul>
  <li><p>In the network tab, I get <code>status code 200</code>.</p></li>
  <li><p>Read-write-execute permissions for the target folder <code>images</code> on the server are (temporarily, for testing!) set to <code>777</code>, <code>(rwxrwxrwx)</code>. </p></li>
  <li><p>I tested different files and different folder names (new and existing), but the files I try to upload never show up.</p></li>
  <li><p>I noticed that despite using <code>mkdir($path, 0777, true);</code> in my code to create the folder, the folder on the server has then permissions set to <code>705</code>, <code>(rwx---r-x)</code>. </p></li>
  <li><p>The only changes I made to this code from the version that runs just fine on <code>localhost</code> is that I changed <code>$path</code>.</p></li>
  </ul>
  
  <p><strong>Error message I'm getting:</strong></p>
  
  <pre><code>Warning: mkdir(): Read-only file system in /path/to/scripts/process/process.php on line 31
  /folder/data/uploads/images/test/image.webp -- 
  Warning: move_uploaded_file(/folder/data/uploads/images/test/image.webp): failed to open stream: No such file or directory in /path/to/scripts/process/process.php on line 75
  </code></pre>
  
  <p>And accordingly:</p>
  
  <pre><code>Warning: move_uploaded_file(): Unable to move (...)
  </code></pre>
  
  <ul>
  <li>Line 31 is <code>mkdir($path, 0777, true);</code></li>
  <li>Line 75 is <code>move_uploaded_file($file_tmp, $file);</code></li>
  </ul>
  
  <p><strong>I found several fixes for Linux file systems for this issue. But how can I go about this when using shared hosting?</strong></p>
  
  <p>This is my first time attempting this and help is much appreciated.</p>