19

I'm using curl and php to upload file. I need help to set a custom request header keys like

X-Filename  blahblah.zip
X-Filesize  2677
X-Filetype  application/zip

2 Answers 2

33

You must use the curl_setopt() function, and its CURLOPT_HTTPHEADER option (quoting) :

An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100')


Basically, in your case, you'd have something like this :

$headers = array(
    'X-Filename: blahblah.zip', 
    'X-Filesize: 2677', 
    'X-Filetype: application/zip', 
);
curl_setopt($your_resource, CURLOPT_HTTPHEADER, $headers);
Sign up to request clarification or add additional context in comments.

2 Comments

Does this overwrite the currently set headers, or merge into the existing headers?
It does overwrite, unfortunately.
6
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Filename: blahblah.zip', 'X-Filesize: 2677', 'X-Filetype: application/zip'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.