I am a web developer / music producer. and I'm working on my personal website. I am using the jplayer
jquery Plugin + Php Curl
to retrieve the file. However I'm getting a 301 error permanently moved
???? I don't understand why I'm getting this. I sent the content type header for audio/mepeg but no results .
HTML markup:
<?php
function beats(){
// <li><a href="hosts/beats/1.mp3" class="track track-default">1</a></li>
$beats = array("...."=>md5(1),"...."=>md5(2),"....."=>md5(3));
foreach($beats as $key=>$value){
echo "
<li><a href=\"hosts/beats/beat.php?".md5('url')."=$value\" class=\"track\">$key</a></li>";
}
}
?>
<ul class="playlist">
<li><span>Select a track : </span></li>
<? Beats(); ?>
</ul>
php curl file:
<?php
if(isset($_REQUEST[md5('url')])){
$beats = array(1=>md5(1),2=>md5(2),3=>md5(3));
foreach($beats as $beatFile=>$url){
if($_REQUEST[md5('url')] == $url){
$BeatFile = $beatFile;
}
}
$url = $BeatFile.".mp3";
// Initializing curl
$ch = curl_init($url);
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('type=audio/mpeg') ,
CURLOPT_POSTFIELDS => $url
);
// Setting curl options
curl_setopt_array($ch,$options);
// Getting results
$beat = curl_exec($ch);
echo $beat;
}else{
echo "No Permission";
}
?>
The server is redirecting you, but cURL's default behavior is to ignore redirects. Turn the option CURLOPT_FOLLOWLOCATION
on to follow the 301 redirect.
Also, you should remove your CURLOPT_HTTPHEADER
. There is no such header as type=
, and even if there was, it would apply to the response and not the request.