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

主宰稳场 提交于 2019-12-10 13:53:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!