我正在使用Soundcloud API(1.1)从我的电脑上传曲目,但在上传时却给我一个'<error> 401 - Unauthorized</error>' (length=33)
错误。
$ mimes = array('aac'=&gt;'video / mp4','aiff'=&gt;'audio / x-aiff','flac'=&gt;'audio / flac','mp3'= &gt;'audio / mpeg','ogg'=&gt;'audio / ogg','wav'=&gt;'audio / x-wav' );
$extension = explode('.', $_FILES['file']['name']);
$extension = (isset($extension[count($extension) - 1]))
? $extension[count($extension) - 1] : NULL;
$mime = (isset($mimes[$extension])) ? $mimes[$extension] : NULL;
if (isset($mime)) {
$tmp_file = $tmp_path . date("ymdhis") . $_FILES['file']['name'];
if (move_uploaded_file($_FILES['file']['tmp_name'], $tmp_file)) {
$post_data = array( 'track[title]' => 'test title',
'track[asset_data]' => $tmp_file, 'track[sharing]' => 'public' );
if ($response = $soundcloud->upload_track($post_data, $mime)) {
var_dump($response);
$response = new SimpleXMLElement($response);
$response = get_object_vars($response);
print_r($response);
$message = 'Success! <a href="' . $response['permalink-url'] . '">Your track</a> has been uploaded!';
unlink(realpath($tmp_file));
} else {
var_dump($response);
$message = 'Something went wrong while talking to SoundCloud, please try again.';
}
} else {
$message = 'Couldn\'t move file, make sure the temporary path is correct';
}
} else {
$message = 'SoundCloud support .mp3, .aiff, .wav, .flac, .aac, and .ogg ';
}
echo $message;