使用CURL在服务器中下载特定文件夹中的MP4视频

时间:2017-11-14 09:17:58

标签: php curl video ffmpeg

我正在尝试下载.MP4 Extension文件,PHP Code In Specific Folder我的代码仅适用于.MP4扩展程序,但我无法使用此代码下载此URL MP4视频

  

https://r3---sn-vgqsrnel.c.doc-0-0-sj.sj.googleusercontent.com/videoplayback?itag=18&key=yt6&source=youtube&mime=video%2Fmp4&sparams=dur%2Cei%2Cid%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Csource%2Cexpire&mv=m&ipbits=0&ratebypass=yes&ms=au&mn=sn-vgqsrnel&pl=28&mm=31&dur=296.147&id=o-AGGQKzVE4Kx-vQgQkb_7v_-2v8RJEP8bYukfJukhn8PM&expire=1510672628&lmt=1510636913694890&ip=107.178.194.23&mt=1510650948&ei=lLQKWoz2NcruDrDrikg&signature=B548DE94A6C594DE473F900D22D3A2685FBEBDED.126ED86D280FC8A4B1FF33B62A6F02EFC0E43576

我正在尝试此代码

    function download ($url, $location){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSLVERSION,3);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $data = curl_exec ($ch);
    $error = curl_error($ch);
    curl_close ($ch);


    $file = fopen($location, "wb");
    fwrite($file, $data);
    fclose($file);
    return 'done';
    }
    ?>
    <!DOCTYPE html>
    <html>
    <body>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    Video URL (Only With .MP4 Extension): 
    <input type="text" name="url" placeholder="Video URL Here" required/><br>
    Video ID Number:
    <input type="text" name="id" placeholder="Video ID Nmber eg:1,2,3" required/><br>
    <input type="submit"/>
    </form>
    </body>
    </html>
    <?php 
    @$url = $_POST['url'];
    @$ID = $_POST['id'];
    $SCRIPT_DIR = dirname(__FILE__);
    $TEMP_DIR = $SCRIPT_DIR . '/videos/'; 
    $location = $TEMP_DIR . $ID . '.mp4';
    if(isset($_POST['url'])){

        echo download($url, $location);

    }

1 个答案:

答案 0 :(得分:1)

之前我使用过此代码从同一来源下载视频:

function download ($url, $location){
  $fp = fopen($location, "w+");
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  curl_setopt($ch, CURLOPT_FILE, $fp);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_exec($ch);
  curl_close($ch);
  fclose($fp);

  return 'done';
}