最近碰到一個需要在PHP端使用curl上傳檔案

一直發生message: "Required request part 'file' is not present"錯誤

 

後來才找到正確用法

重點在CURLOPT_POSTFIELDS中的file參數,必須加上curl_file_create($fileName)才會正確。

ex: 

$params = array(
     "file" => curl_file_create(realpath($fileName)),
);

--

參考自

https://stackoverflow.com/questions/14646653/curl-not-sending-file-to-api-call

http://rocksaying.tw/archives/35970791.html

 

arrow
arrow
    全站熱搜

    dizzy03 發表在 痞客邦 留言(0) 人氣()