大家好!我有 curl 命令(音频文件上传):
curl -k -v -H "Expect: " -H "Content-Type:application/octet-stream" --data-binary '@/Path/To/File/test.wav' -X POST 'https://myapi.com?param1=xxx¶m2=yyy'
文件已成功上传且可读。但是当我使用 php 脚本时:
$filename = 'test.wav';
$file = '@/Path/To/File/test.wav';
$post_url = "https://someapi.com?param1=xxx¶m2=yyy";
$post_str = array("$filename" => $file);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/octet-stream'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$http_body = curl_exec($ch);
var_dump($http_body);
文件成功上传并且 test.wav 无效(有一些错误)。我在脚本中做错了什么?