问题
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...
回答1:
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
来源:https://stackoverflow.com/questions/14010346/should-i-set-curlopt-upload-when-i-post-file-with-curl-in-php