php - Get the real video URL from a url -
i'm trying real file url url doesn't show real file name.
my url http://video.premium.com/file/ee7bfec921cfbe16e6f08e282992b99670a00ca3/3
if real file url stream directly online through web player, needs .mp4 or other file format play, url http://video.premium.com/file/ee7bfec921cfbe16e6f08e282992b99670a00ca3/3 doesnt work.
but when open url using vlc media player, works. doesn't work online flash or other players..
is possible? anyway this?
with curl, use this: follows redirect until finds endpoint. in included code used goo.gl shorten url rando image. see output original link (and output whatever number of redirects , urls), , final redirect actual file. think looking for. did not write originally, found somewhere time ago , reused many times again tweaking when needed. seems fit in many places. glad pass on. think might achieve looking for.
<?php function follow_redirect($url){ $redirect_url = null; if(function_exists("curl_init")){ $ch = curl_init($url); curl_setopt($ch, curlopt_header, true); curl_setopt($ch, curlopt_nobody, true); curl_setopt($ch, curlopt_returntransfer, true); $response = curl_exec($ch); curl_close($ch); } else{ $url_parts = parse_url($url); $sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80)); $request = "head " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " http/1.1\r\n"; $request .= 'host: ' . $url_parts['host'] . "\r\n"; $request .= "connection: close\r\n\r\n"; fwrite($sock, $request); $response = fread($sock, 2048); fclose($sock); } $header = "location: "; $pos = strpos($response, $header); if($pos === false){ return false; } else{ $pos += strlen($header); $redirect_url = substr($response, $pos, strpos($response, "\r\n", $pos)-$pos); return $redirect_url; } } $url = 'http://goo.gl/66vjb'; echo '<ol>'; while(($newurl = follow_redirect($url)) !== false){ echo '<li>', $url, '</li>'; $url = $newurl; } echo '</ol>'; echo '<a href="', $url, '">', $url, '</a>'; ?> output:
http://1.bp.blogspot.com/_xe0tdw07noo/tosvqxztgai/aaaaaaaaelo/ag80jz7u_fo/s1600/aptitude_test.gif
Comments
Post a Comment