title: trying to upload file in server (mamp) using php
body: <p>I have an <code>angular</code> page where I load file, then I call my <code>php</code> code to upload to file into my <code>server</code>.</p>
  <p>It does not work and I got this error for php :</p>
  <pre><code>Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/test/my-dropzone-app/upload.php on line 11
  </code></pre>
  <p>php code :</p>
  <pre><code>&lt;?php
    
  header(&quot;Access-Control-Allow-Origin: *&quot;);
  header(&quot;Access-Control-Allow-Methods: PUT, GET, POST&quot;);
  header(&quot;Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept&quot;);
     
  $folderPath = &quot;http://localhost:8888/test/my-dropzone-app/upload/&quot;;
  $postdata = file_get_contents(&quot;php://input&quot;);
  $request = json_decode($postdata);
     
  foreach ($request-&gt;fileSource as $key =&gt; $value) {
     
      $image_parts = explode(&quot;;base64,&quot;, $value);
     
      $image_type_aux = explode(&quot;image/&quot;, $image_parts[0]);
     
      $image_type = $image_type_aux[1];
    
      $image_base64 = base64_decode($image_parts[1]);
    
      $file = $folderPath . uniqid() . '.'.$image_type;
    
      file_put_contents($file, $image_base64);
  }
  
  ?&gt;
  </code></pre>
  <p>angular :</p>
  <pre><code>  onSelect(event) {
        console.log(event);
        this.files.push(...event.addedFiles);
  
        const formData = new FormData();
    
        for (var i = 0; i &lt; this.files.length; i++) { 
          formData.append(&quot;file[]&quot;, this.files[i]);
        }
   
        this.http.post('http://localhost:8888/test/my-dropzone-app/upload.php', formData)
        .subscribe(res =&gt; {
           console.log(res);
           alert('Uploaded Successfully.');
        })
    }
  </code></pre>