-3
I set up a code to use on a radio that I own, pulling the cover of the song that is currently playing, but it only works on the localhost. When I enter the site, only the default image I placed appears (In case the server does not find the album image).
Could someone help me know why?
No PHP or any other error appears. Only the image of the server cover is not loaded, and is instead the default...
$ip = "radioculturanf.ddns.net";
$port = "8000";
$api = "d5b942eae610872b133ca1f73bcbd3fe"; // 70bf8c268d5ea9d7d78a4f47e3b8ef35 57ee3318536b23ee81d6b27e36997cde
$fp = @fsockopen($ip,$port,$errno,$errstr,1);
if (!$fp) {
$title = "Rádio fora do ar! ";
} else {
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp)) {
$info = fgets($fp);
}
$info = str_replace('</body></html>', "", $info);
$split = explode(',', $info);
if (empty($split[6])) {
$title = "Título não disponível ";
} else {
$count = count($split);
$i = "6";
while($i<=$count) {
if ($i > 6) {
@$title .= ", " . $split[$i];
} else {
@$title .= $split[$i];
}
$i++;
}
}
}
$title = "@".substr($title, 0, -2)."#";
function get_string_between($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
$artista1 = get_string_between($title, '@', '- ');
$faixa1 = get_string_between($title, ' -', '#');
$artista = str_replace(" ", "+", trim($artista1));
$artista_final = str_replace("&", "&", $artista);
$artista_final = str_replace(",", "", $artista_final);
$faixa = str_replace(" ", "+", trim($faixa1));
$faixa_final = str_replace("&", "&", $faixa);
$faixa_final = str_replace(",", "", $faixa_final);
$api_include = file_get_contents('http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key='.$api.'&artist='.$artista_final.'&track='.$faixa_final.'', TRUE);
function get_string_between_api($string_api, $start_api, $end_api){
$string_api = ' ' . $string_api;
$ini_api = strpos($string_api, $start_api);
if ($ini_api == 0) return '';
$ini_api += strlen($start_api);
$len_api = strpos($string_api, $end_api, $ini_api) - $ini_api;
return substr($string_api, $ini_api, $len_api);
}
$imagem = get_string_between_api($api_include, '<image size="large">', '</image>');
if(empty($imagem)){
$img_fin = "cd.jpg";
}else{
$img_fin = $imagem;
}
$img_total = str_replace("%20/%3E%3C/div%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20class=", "", $img_fin);
$img_total2 = '<img src='.$img_total.' />';
echo '
<div class="media">
<p>'.$img_total2.'</p>
<p><span class="artista">'.$artista1.'</span></p>
<p><span class="faixa">'.$faixa1.'</span></p>
</div>
';
Please provide more details, what error, message is getting on the production server?
– lazyFox
No error appears, just don’t load the album cover image. Using this code on localhost, everything works. Already when accessing via site, just loads the default image, which is not making the least sense to me! hahahah
– ledlemos
Please [Edit] your post clarifying all points necessary to avoid closing, preferably with the errors indicated in the PHP log. Taking advantage, it would be good to use the correct tags.
– Bacco
I’m sorry but it looks like you’re putting the $img_total2 inside the echo, and you’re not attributing anything to it.
– Rovann Linhalis
Bacco: I tried to edit but he was cutting the code. I didn’t understand why...
– ledlemos
Rovann: Look at the link I provided above. Everything is working perfectly here on localhost. And I do not know if you saw by the code that was in the body of the question. He cut some parts. In the link I left there is correct! rsrs
– ledlemos
Seems to be a problem with addressing, check the details of
.htaccess
in use. However, please edit the question, providing more details, and code in use if possible.– Edilson
Press F12 if it’s Chrome and go to the "Console" tab, see what errors have occurred.
– Guilherme Nascimento
The easiest way to add code to the body of the text is to open it in the text editor and add a tab level to the lines. Then just copy and paste
– Guilherme
I managed to enter the code. Finally! rsrs No error, Guilherme.
– ledlemos