Jump to content

Help In php coding


buddhika2010

Recommended Posts

Made this up just for you and tested it even.

 

<?php
function checkLiveMp3($url){
$context = stream_context_create(array(
    'http' => array(
        'timeout' => 1
    )
));
$the_contents = @file_get_contents($url, 0, $context);
if (empty($the_contents))
{
echo "$url is Dead<br />";
echo "Insert some code here for an error or other code.<br />";
echo "<br /><hr>";
} else {
$mp3_check = substr("$url", -4);
if ($mp3_check != ".mp3") {
echo "$url is alive but not mp3 file<br />";
echo "Insert some code here for an error or other code.<br />";
echo "<br /><hr>";
} else {
echo "Alive and mp3 file<br />";
echo "Insert some code here so some music can play.<br />";
echo "Mp3: <a href='$url'>$url</a>";
echo "<br /><hr>";
}
}
}

?>
<?php
//Usage
$url = "http://www.wyntonmarsalis.org/audio/tribute/wyntonstribute.mp3";
checkLiveMp3($url);

checkLiveMp3("http://somesite.com/something.jpg");

checkLiveMp3("http://www.sotone.com/samples/!2-Shapiro_Brahms.1st.mvmt.mp3");

?>

Link to comment
https://forums.phpfreaks.com/topic/222349-help-in-php-coding/#findComment-1150219
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.