I'm trying to upload a file to a remote server using curl.

The server requires that the file contents should be in the post body and the file name should be in the header.

This is the code I', using :

$fp = fopen($fileLocation, "r");
	$ch = curl_init();
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($fileLocation));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_URL, $destinationServer);

    $header = array(
		"fileName: $fileID"

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);

The above code sends the file OK but the header received at the server does not contain the fileName value.
Whats wrong here?

Recommended Answers

Did you echo out "fileName: $fileID" to see what the actual value being passed was?

Jump to Post

All 4 Replies

Did you echo out "fileName: $fileID" to see what the actual value being passed was?

Yes I did. Also tried using different data, no change.

Is there a way to check the whole POST data BEFORE it is posted?

you may put on your curl : curl_setopt($ch, CURLOPT_HEADER, 1);
try to change : curl_setopt($ch, CURLOPT_HEADER, TRUE);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.