Take the 2-minute tour ×

My code to upload the file on the REMOTE server doesn't seem to be working. When uploading the file from the browser at the link, all the contents of csv file is committed to the database. Here is the code:

function postToDB()
  $fp = fopen('./errorLog.txt', 'w+');
  $csvFile = fopen('./myFile.csv', 'r');

  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 100);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_USERPWD, ":password");
  curl_setopt($ch, CURLOPT_PUT, true);

  curl_setopt($ch, CURLOPT_INFILE, $csvFile);
  curl_setopt($ch, CURLOPT_VERBOSE, true);
  curl_setopt($ch, CURLOPT_STDERR, $fp);

  if (!curl_exec($ch))
     echo "Error: ".curl_error($ch);
     echo "Success";

Strangely, the code echoes "Success". But I don't find the database updates taking place with the code above even though "Success" is echoed.

Can anyone help me find the issue here?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This is because your submitting the raw CSV data, and its not encoded into field=value pairs as form post data is. The easiest way to deal with this is on the server to just use:

$csvfile = file_get_contents("php//input");
share|improve this answer
I did not get you. You mean I cannot post from my code? –  name_masked Jun 4 '11 at 0:40
You can, but you need to read up on RFC 2616 w3.org/Protocols/rfc2616/rfc2616.html –  Geoffrey Jun 4 '11 at 1:28
Also since your posting a file, you need to look at RFC 1341 - w3.org/Protocols/rfc1341/7_2_Multipart.html –  Geoffrey Jun 4 '11 at 1:31
Or, you could give this class a go, not sure though if it works as I just googled it for you - phpclasses.org/package/… –  Geoffrey Jun 4 '11 at 1:32

Your Answer


