954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

CURLOPT_HTTPHEADER problem

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?

psyb0rg
Newbie Poster
18 posts since May 2008
Reputation Points: 10
Solved Threads: 1
 

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

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

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

psyb0rg
Newbie Poster
18 posts since May 2008
Reputation Points: 10
Solved Threads: 1
 

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

psyb0rg
Newbie Poster
18 posts since May 2008
Reputation Points: 10
Solved Threads: 1
 

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

gieseni
Newbie Poster
1 post since May 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: