使用函数file_get_contents()的结果很奇怪

时间:2016-02-13 16:23:42

标签: php

我正在尝试使用该工具获取网址的内容 的file_get_contents( 'http://player.vimeo.com/external/155119694.sd.mp4?s=56e2df64c6b098a7c9a7402c7f6179201e44a029&profile_id=112&oauth2_token_id=407699588'); 但结果很奇怪,有人可以告诉我为什么这个结果?

ftypmp42mp42mp41isomavc1>moovlmvhdÒã-[ãã-[X!Y @ * iods€€€ÿÿÿÿÿÿÿÿÿÿÿÿÿÿtrak\tkhdÒã–[Òã–[!*@€h$edtselst!*Ømdia mdhdÒã–[Òã–[UÄ6hdlrvideL-SMASH Video Handlerzminfvmhd$dinfdrefurl :stblÃstsd³avc1€hHH AVC Codingÿÿ:avcCdÿágd¬Ù@ /ùp À ¨@xÁŒ°hëì²,ýøøcolrnclxpaspsttsèctts$stss=yµñ'sdtp¦––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––š¦––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––š¦––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––š¦––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš––š¦––šš––šš––šš––šš––šš––šš––šš––šš––šš––šš–š(stsc €stszÿ€ ÈüFB›w‚“cÑEÓ&gt;&lt; Ò!I90EÿC+Ì%X&lt; < em>1CF½D&gt; [/]æç#Ö'4mAMoX5g“{pU,°¾&lt; ¬I'j{q1)4ê$ê')6'%üO)P0,jDÌX”k“£CëqH,FT $¢:3jÿ’%)õc2-óƒ>?J=ן| 0‡[ïqH#bOžk/¶e1°RÙN+ Q =)!(ßN+! - + UcT-9O4õgHU&lt; )!`;HstcoËð'VÅì5ɺ< |Øij“*¥§T|nòÀsgpdrollsbgprolltrak\tkhdÒã-[ãã - [!Y @ $ edtselst!YmdiamdhdÒã-[Òã - [»€lUÄ6hdlrsounL-SMASH音频处理程序·minfsmhd $ dinfdrefurl {stblgstsdWmp4a»€3esds€€€” €€««¯0€€$$$$ stts>(stsc /€stsz>,«qsjW9。+ 0!%&amp;“,ûûþ3$? - ! - )üîðûúõ,TCýÿþ&amp; 6”%;ýÿ 9þKDI‡ùþ,*ÿ?Œb%þþyù÷ýJD.ô-ö(óýûþOFÿþKúü&amp;#Q $û1&gt; D}1ûúùÿþ-M!9(þI!-oú 0JLø“#&amp; RE?ûy&lt; øùÿ'&amp;öüKLÿþþûùNÿ #T;üüþ; rùþhúù&amp;0E0Kü1ü16ûLstco‰D¾$“¹œwçzXõ| - ì^tñÒ&lt;&amp;4í'free×mdatÿÿÿÜEé½æÙH· - ,ØÙ#îïx264 - core 148 r11 a01e339 - H.264 / MPEG-4 AVC编解码器 - Copyleft 2003-2016 - http://www.videolan.org/x264.html - 选项:cabac = 1 ref = 3 deblock = 1:0:0 analyze = 0x3:0x113 me = hex subme = 7 psy = 1 psy_rd = 1.00:0.00 mixed_ref = 1 me_range = 16 chroma_me = 1 trellis = 1 8x8dct = 1 cqm = 0 deadzone = 21,11 fast_pskip = 1 chroma_qp_offset = -2 threads = 11 lookahead_threads = 1 sliced_threads = 0 nr = 0 decimate = 1 interlaced = 0 bluray_compat = 0 stitchable = 1 constrained_intra = 0 bframes = 3 b_pyramid = 2 b_adapt = 1 b_bias = 0 direct = 1 weightb = 1 open_gop = 0 weightp = 2 keyint = infinite keyint_min = 20 scenecut = 40 intra_refresh = 0 rc_lookahead = 40 rc = 2pass mbtree = 1比特率= 750 ratetol = 1.0 qcomp = 0.60 qpmin = 5 qpmax = 69 qpstep = 4 cplxblur = 20.0 qblur = 0.5 vbv_maxrate = 825 vbv_bufsize = 900 nal_hrd = none filler = 0 ip_ratio = 1.40 aq = 1:1.00€ü是“ÿþÇóøº•” EASD,)}; €!ÓŽa-™¾zŽOYJ4©LŽ°;oËãf·Ìpó[AÔÊ4jé%•;ÉZa\Ò/ $ 6 +ä«4fLyiƒ×«gc¹Í)þåμŠV - @ <ý'M>²2“F,øy³6¹ !ó6Ïû1••U:?!LY '#Š¨ý7ðýS2¢¼€žbvRKO¼îª¸û•' àË1¸lL°t'ÂQ©†eå7ºòƒè¾ÃJALnSYU * NPC³iñ2¥R6»AP©6AV〜4f7ï0s)AAE

1 个答案:

答案 0 :(得分:2)

您正在谈论的网址:

http://player.vimeo.com/external/155119694.sd.mp4?s=56e2df64c6b098a7c9a7402c7f6179201e44a029&profile_id=112&oauth2_token_id=407699588

...是 - 在这种情况下 - 重定向到不同的URL(您可以通过浏览器轻松验证它):

https://fpdl.vimeocdn.com/vimeo-prod-skyfire-std-us/01/1023/6/155119694/480188332.mp4?token=56bf93f0_0x229f060ec6a77cfd556b0e21fec1171b822cd30c

如果要将其本地存储到客户端工作站,则代码可能如下所示:

代码

<?php

    $url_original = 'http://player.vimeo.com/external/155119694.sd.mp4?s=56e2df64c6b098a7c9a7402c7f6179201e44a029&profile_id=112&oauth2_token_id=407699588';
    $url_redirected = '';

    // Get redirection
    $headers = get_headers($url_original,1);
    $url_redirected = $headers['Location'][1];
    echo "<p>Original URL = <br />$url_original </p>";
    echo "<p>Redirected URL from \$headers['Location'][1] = <br />$url_redirected </p>";
    // echo 'All the headers:<pre>'; print_r($headers); echo '</pre>';

    // Get the file from the original server
    $video = file_get_contents($url_redirected);

    // Store the file to local server
    // $filename = '/downloaded_video.mp4';
    $filename = dirname(__FILE__) . '/downloaded_video.mp4';
    file_put_contents($filename , $video); 

    // Download to the client workstation
    header('Content-Disposition: attachment; filename=downloaded_video.mp4');
    header('Content-type: video/mp4');
    echo $video;

?>

备注

  • 此代码尚未经过测试。
  • 重定向会添加一个令牌,该令牌会在每次发出请求时发生更改。
    此令牌可能会超时,当超时时,必须重复使用原始URL的请求才能获得带有重定向的URL有效令牌。你可以称之为&#34;黑客预防&#34;。
  • 您现在已经使用此网址进行了一系列操作 - 希望能够学习!