title: Not passing CSV file in cURL POST correctly in PHP
body: <p>I am trying to send a POST request to an API and part of that request I am adding a CSV file to get return tokens based on the emails and numbers I provide. The first few lines of code use data that I retrieve from my database, and that as well as generating the file and populating it with text data is correct. The problem is with my cURL. When I make this request in PostMan, the result is perfectly fine, and I actually used the PHP-curl generated code from PostMan to write this request. However, the line</p>
  
  <pre><code>filename=\"".$filename."\"\r\n 
  </code></pre>
  
  <p>does not, for some reason, bring up the file that was just correctly populated before, and the API log says that the file has no data in it. Both files are located in the same directory, so I really am at a loss for what I'm doing incorrectly.   </p>
  
  <pre><code>$file = fopen($filename, "w");
  
  while ($row2 = mysqli_fetch_array($query2)){
      $txt = "$row2[email], $row2[firstname], $row2[lastname], 
      $row[company], $row2[mobilephone]\n";
      echo $txt;
      fwrite($file, $txt);
  }
  
  $curl = curl_init();
  
  echo $filename."\n";
  
  curl_setopt_array($curl, array(
      CURLOPT_URL =&gt; "https://example.com",
      CURLOPT_RETURNTRANSFER =&gt; true,
      CURLOPT_ENCODING =&gt; "",
      CURLOPT_MAXREDIRS =&gt; 10,
      CURLOPT_TIMEOUT =&gt; 30,
      CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST =&gt; "POST",
      CURLOPT_POSTFIELDS =&gt; "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n
          Content-Disposition: form-data; 
          name=\"token\"\r\n\r\12345\r\n
          ------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n
          Content-Disposition: form-data; name=\"datafile\";
          filename=\"".$filename."\"\r\n
          Content-Type: text/csv\r\n\r\n\r\n
          ------WebKitFormBoundary7MA4YWxkTrZu0gW--",
      CURLOPT_HTTPHEADER =&gt; array(
          "cache-control: no-cache",
          "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
      ),
  ));
  
  $response = curl_exec($curl);
  $err = curl_error($curl);
  
  if ($err) {
      echo "cURL Error #:" . $err;
  } else {
      echo $response;
  }
  </code></pre>
  
  <p>Can anyone spot what I am doing incorrectly here?</p>
  
  <blockquote>
    <p>NOTE: I have replaced several fields and strings with dummy data for privacy/security reasons</p>
  </blockquote>