Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I set CURLOPT_UPLOAD when I POST file with cURL in PHP?

When I try to set it, it forces the request method to be PUT.

Here is what I put in CURLOPT_POSTFIELDS:

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'fileUpload' => '@/home/apache/upload/dummy.sql'
));

Or should I ignore the CURLOPT_UPLOAD at all? It said prepare for file upload...

like image 919
Vicary Avatar asked Dec 23 '12 10:12

Vicary


1 Answers

You can safely ignore it. CURLOPT_POSTFIELDS is just enough to upload a file. The curl library will recognize the file upload and set what's required internally itself.


The idea behind CURLOPT_UPLOAD is to tell curl to use PUT method, add some common file uploading headers for that such as Expect: 100-continue header and use chunked encoding to upload a file of unknown size if you are using HTTP/1.1

like image 99
Alex Avatar answered Oct 18 '22 16:10

Alex