上传曲线,卷曲,echonest POST问题与本地文件
问题描述:
我想通过echonest api上传文件(输入类型和命名为“上传”),但我努力让卷曲上传工作。上传曲线,卷曲,echonest POST问题与本地文件
http://developer.echonest.com/docs/v4/track.html#upload
任何人都可以点我到正确的方向,以获得数据的二进制和标题:应用程序/八位字节流POST方法的工作。 这是一个内容类型为“application/octet-stream”的HTTP POST请求,本地文件作为请求的主体,以及URL中的参数。
卷曲PHP:
$localfile = $_FILES['upload']['name'];
$fp = fopen($localfile, 'r');
$post = array('$localfile'=>'@$localfile','api_key'=>'xx','filetype'=>'mp3');
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); // --data-binary
curl_setopt($ch, CURLOPT_URL, 'http://developer.echonest.com/api/v4/track/upload');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, 'Content-type: application/octet-stream');
$response = curl_exec($ch);
$result = json_decode($response,true);
$id = $result['response']['track']['id'];
curl_close($ch);
fclose($fp);
echo $id;
答
这个问题可能有一些做与您使用的变量单引号字符串中。此外,不正确使用@
符号。试试这个......
array("$localfile"=>"$localfile",'api_key'=>'xx','filetype'=>'mp3');
虽然这看起来不正确。你可能想要这个..
array("localfile"=>"$localfile",'api_key'=>'xx','filetype'=>'mp3');