title: How to set 'Access-Control-Allow-Credentials' header to upload a file in angular 4?
body: <p>I am working on angular 4 app, In which, I have a requirement to upload a file on form submit, for this I am using ng2-file-upload plugin. But I faced a problem to upload file. I am creating a upload.php file completing uploading process. 
  upload.php is as follow: </p>
  
  <pre><code>header("Access-Control-Allow-Origin: http://localhost:4200");
  header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  
  if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo json_encode(array('status' =&gt; false));
    exit;
  }
  
  $path = 'uploads/';
  
  if (isset($_FILES['file'])) {
  $originalName = $_FILES['file']['name'];
  $ext = '.'.pathinfo($originalName, PATHINFO_EXTENSION);
  $generatedName = md5($_FILES['file']['tmp_name']).$ext;
  $filePath = $path.$generatedName;
  
  if (!is_writable($path)) {
    echo json_encode(array(
      'status' =&gt; false,
      'msg'    =&gt; 'Destination directory not writable.'
     ));
     exit;
   }
  
  if (move_uploaded_file($_FILES['file']['tmp_name'], $filePath)) {
     echo json_encode(array(
       'status'        =&gt; true,
       'originalName'  =&gt; $originalName,
       'generatedName' =&gt; $generatedName
     ));
   }
  }
  else {
    echo json_encode(
      array('status' =&gt; false, 'msg' =&gt; 'No file uploaded.')
    );
   exit;
   }
  </code></pre>
  
  <p>But I have got following error:</p>
  
  <blockquote>
    <p>Failed to load <a href="http://localhost/uploads/uploads.php" rel="nofollow noreferrer">http://localhost/uploads/uploads.php</a>: Response to
    preflight request doesn't pass access control check: The value of the
    'Access-Control-Allow-Credentials' header in the response is '' which
    must be 'true' when the request's credentials mode is 'include'.
    Origin '<a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a>' is therefore not allowed access. The
    credentials mode of requests initiated by the XMLHttpRequest is
    controlled by the withCredentials attribute.</p>
  </blockquote>
  
  <p>If any help, please suggest me, thanks in advance!</p>