【发布时间】:2017-08-03 16:57:07
【问题描述】:
我正在使用 sonicAPI 尝试上传文件。出于某种原因,我不能在 php 中使用 curl 来执行此操作,因为他们的 api 需要标志 -F 来模拟从表单中发布....((HTTP)这让 curl 模拟用户按下提交的填写表单按钮)
无论如何。我必须使用
exec("$curl https://api.sonicapi.com/file/upload?access_id=$accessId -Ffile=@./shortaudio.mp3 2>&1", $output, $exit);
上传文件。引号中的命令在直接输入 shell 时有效。它返回一个 xml 字符串。但是,当我使用 var_dump($output) 时,我只是获得了在实际 shell 中执行时并未实际显示的“加载”信息。我明白了
array(4) {
[0]=>
string(79) " % Total % Received % Xferd Average Speed Time Time Time Current"
[1]=>
string(77) " Dload Upload Total Spent Left Speed"
[2]=>
string(158) "
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 17008 100 249 100 16759 393 26489 --:--:-- --:--:-- --:--:-- 26517"
[3]=>
string(249) ""
}
如何获取应该返回的 xml 字符串?该文件确实已成功上传,因此应该有一个 xml 响应。 或者,如果没有,我如何通过 php curl 模拟表单发布?
【问题讨论】:
-
你应该可以在 PHP (5.5+) 中使用CURLFile
-
嗯...仍然收到 400 错误。使用这个 $cfile = curl_file_create("shortaudio.mp3",'multipart/form-data','shortaudio');