title: HTTP status codes for file uploading in PHP
body: <p>I'm trying to develop a REST-like PHP script able to accept a POST request to upload files. I need to define the HTTP request and response syntax, beside the HTTP standard of course.</p>
  
  <p>I'm trying to find the best HTTP status codes corresponding to each possible PHP error. You'll see what I found so far below.</p>
  
  <p>I'm not entirely sure of all of them (I'm open to suggestions), but my biggest concern is that they match only if one file was uploaded. </p>
  
  <p>How do I manage multiple file uploading?</p>
  
  <p>The problem remains if the upload is atomic or if it isn't (if an error on one file cancel the entire upload or if it doesn't).</p>
  
  <hr>
  
  <ul>
  <li><code>$_FILES[]['error']</code>:
  
  <ul>
  <li><code>UPLOAD_ERR_INI_SIZE</code>: 413 (too big)</li>
  <li><code>UPLOAD_ERR_FORM_SIZE</code>: 413 (too big)</li>
  <li><code>UPLOAD_ERR_PARTIAL</code>: 409 (try again)</li>
  <li><code>UPLOAD_ERR_NO_FILE</code>: 204 (no file in request, nothing to do)</li>
  <li><code>UPLOAD_ERR_NO_TMP_DIR</code>: 500 (conf' problem)</li>
  <li><code>UPLOAD_ERR_CANT_WRITE</code>:
  
  <ul>
  <li><code>!is_writable()</code>: 500 (temp dir not writable)</li>
  <li><code>$_POST['MAX_FILE_SIZE'] &gt; disk_free_space()</code>: 507 (not enough space in temp dir)</li>
  <li>500 (unknown server problem while writing temp file)</li>
  </ul></li>
  <li><code>UPLOAD_ERR_EXTENSION</code>: 409 (try again, maybe stopped by user)</li>
  <li><code>UPLOAD_ERR_OK</code>: 
  
  <ul>
  <li><code>!is_uploaded_file($_FILES[]['tmp_name'])</code>:
  500 (file at <code>TMPDIR.DIRECTORY_SEPARATOR.$_FILES[]['tmp_name']</code> wasn't actually downloaded, maybe a problem with temp dir path case)</li>
  <li><code>!is_writable()</code>: 500 (target dir not writable)</li>
  <li><code>$_FILES[]['size'] &gt; disk_free_space()</code>: 507 (not enough space in target dir)</li>
  <li><code>file_exists()</code>: 409 (try again, file name is prefixed with timestamp in target dir)</li>
  <li><code>!move_uploaded_file()</code>: 500 (unknown server error while moving uploaded file)</li>
  <li>201 (file successfully uploaded)</li>
  </ul></li>
  </ul></li>
  </ul>