gpt4 book ai didi

php - YouTube-dl服务器直接文件下载

转载 作者:行者123 更新时间:2023-12-03 05:58:07 25 4
gpt4 key购买 nike

我已经在服务器上成功安装了youtube-dl,并且从命令行开始,一切正常运行。

现在,我希望能够从Web浏览器中调用网站上的链接,该链接可直接启动文件的下载。因此,按此顺序:

  • 在浏览器中打开网站(例如http://example.com/download.php?v=as43asx3
  • YouTube-dl处理输入的
  • Web浏览器下载文件
  • 临时文件将从服务器
  • 中删除

    我对此并不十分有经验,但是仍然需要解决此问题。

    最佳答案

    也许有更好的方法可以做到,但是我很乐意看到它,但是,这是我解决的方法:

    <?php
    ignore_user_abort(true);

    //getting ID from URL
    $youtubeID = $_GET['videoID'] ;

    //getting audio file from youtube video via youtube-dl
    exec('~/bin/youtube-dl --verbose --extract-audio -o "~/html/YouTubeDownloader/%(id)s.%(ext)s" '.$youtubeID);

    //downloading file to client/browser
    $filename = $youtubeID.".m4a";
    header("Content-disposition: attachment;filename=$filename");
    header("Content-type: audio/m4a");
    readfile($filename);

    //deleting file again
    unlink($filename);?>

    关于php - YouTube-dl服务器直接文件下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30005667/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com