A 20007 error occurred while using the Sina Weibo API to write a picture bed, and the document said it needed to upload the file with multipart. How do I upload a file using multipart in PHP with the Curl simulation post?
The code I'm using:
$uri = "https://upload.api.weibo.com/2/statuses/upload.json";$data = array ( 'access_token' => '', 'status' => '', 'pic' => ''); $ch = curl_init ();curl_setopt ( $ch, CURLOPT_URL, $uri );curl_setopt ( $ch, CURLOPT_POST, 1 );curl_setopt ( $ch, CURLOPT_HEADER, 0 );curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );$return = curl_exec ( $ch );curl_close ( $ch ); print_r($return);
Reply content:
A 20007 error occurred while using the Sina Weibo API to write a picture bed, and the document said it needed to upload the file with multipart. How do I upload a file using multipart in PHP with the Curl simulation post?
The code I'm using:
$uri = "https://upload.api.weibo.com/2/statuses/upload.json";$data = array ( 'access_token' => '', 'status' => '', 'pic' => ''); $ch = curl_init ();curl_setopt ( $ch, CURLOPT_URL, $uri );curl_setopt ( $ch, CURLOPT_POST, 1 );curl_setopt ( $ch, CURLOPT_HEADER, 0 );curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );$return = curl_exec ( $ch );curl_close ( $ch ); print_r($return);
Look at Curl code should be no big problem, do not know if you are a few values for the reason of empty,
"Pic" = "@/path/to/myfile.jpg",
When your $data is an array, curl will automatically post it in multipart mode.
In addition, the array must be an array of the K=>V format.