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

I'm trying to get the contents of the URL by using the tool file_get_contents('http://player.vimeo.com/external/155119694.sd.mp4?s=56e2df64c6b098a7c9a7402c7f6179201e44a029&profile_id=112&oauth2_token_id=407699588'); But the result is very strange, someone can tell me why this result?

ftypmp42mp42mp41isomavc1›moovlmvhdÒã–[Òã–[X!Y@*iods€€€Oÿÿ)ÿ€€€€€€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Ó><�Ò!I90E ÿC+Ì%X<�1CF½D>[/)æç#Ö'4 mAM oX5g" {pU‚°¾<� ¬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<�)!`;HstcoËð’VÅì 5ɺ‹¦ØÄ³" *¥ §T |nòÀþsgpdrollsbgprolltrak\tkhdÒã–[Òã–[!Y@$edtselst!Ymdia mdhdÒã–[Òã–[»€ lUÄ6hdlrsounL-SMASH Audio Handler·minfsmhd$dinfdrefurl {stblgstsdWmp4a»€3esds€€€"€€€@«¯0€€€€€€stts›(stsc/ €stsz›‚«qsjW9.+0!%&",ûûþ 3$? -!-)üîðûúõ ,TCýÿ þ&6 „%;ýÿ 9þK D I‡ ù øþ ,*ÿ?Œ b%þþ yù÷ý JD.ô-ö(óýûþ OF ÿþK úü & # Q $û 1 >D }1ûúù ÿþ -M! 9(þ I ! -o ú 0JLø " # &RE?û y<�øùÿ'&öüKLÿþþûù ˆ N ÿ #T;ýüþ ;rùþ h úù&0E0K ü1 ü 16 ûLstco‰D¾$“¹œwçzXõ¦—€¡ø^ tñ Ò<&4í'free×mdatÿÿÿÜE齿ÙH·–,Ø Ù#îïx264 - core 148 r11 a01e339 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=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 bitrate=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€üYeˆ„ÿþÇóøº•'ëâSÐ,)}; €!ÓŽa–™¾zŽOYJ4©Lް;oËãf·Ìpó[A ÔÊ4jé%•;ÉZa\Ò/ $6+ä«4fLyiƒ×«gc¹Í)þ嵊V-@‹ý‘M›²2“F‚øy³6¹Â!ó6Ïû1••Ú:lŸ'#Šˆ¨ý7ðýSˆ2¢¼€žbvRKO¼îª¸û•'àË1¸lL°t‘ÂQ©†eå7ºòƒè¾ÃJALn?ŠÝÜ*Npc!³iñ2¥r6»äP©6àv~4f7ï0s)ãÆ

The URL you are talking of:

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

...is - in this case - redirected to a different URL (you can easily verify it by a browser):

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

When you want to store it locally to your client workstation your code could look like this:

Code

<?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;

?>

Notes

  • This code has not been tested though.
  • The redirection adds a token that changes every time the request is made.
    This token probably will time out, and when it is timed out the request with the original URL must be repeated to get a redirection URL with a valid token. You can call this "hacker prevention".
  • You have now a set of manipulations with this URL - hopefully to learn from!