【问题标题】:How to save/download MP4 in Safari (instead of playing the file in quick time pro player)如何在 Safari 中保存/下载 MP4(而不是在快速专业播放器中播放文件)
【发布时间】:2012-05-22 11:43:50
【问题描述】:

我在上传文件夹中上传了一个带有 php 的 .mp4 文件。现在我用下载链接下载它。它在 Safari 浏览器的 Windows 系统上正确下载。但在 mac 系统上,视频文件正在使用 quicktime pro 播放器播放。虽然我只是想下载它。 但它默认播放。这是仅在 safari 浏览器上的问题。有什么办法可以改变这一点。所以默认情况下它不会与quicktime pro player一起播放。

【问题讨论】:

    标签: php macos


    【解决方案1】:

    可能因为您只是链接到文件,所以如果用户的计算机有软件来处理它,它将选择默认运行它(假设用户的计算机设置为方式)。

    如果您使用正确的标题,您可以强制浏览器显示下载对话框提示:

     header("Cache-Control: public");
     header("Content-Description: File Transfer");
     header("Content-Disposition: attachment; filename=$file");
     header("Content-Type: video/mpeg");
     header("Content-Transfer-Encoding: binary");
    

    【讨论】:

      【解决方案2】:

      请使用以下代码,

          if (file_exists($file)) {
              header('Pragma: public');   // required
              header('Expires: 0');    // no cache
              header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
              header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file)).' GMT');
              header('Cache-Control: private',false);
              header('Content-Type: octet/stream');
              header('Content-Disposition: attachment; filename="'.basename($file).'"');
              header('Content-Transfer-Encoding: binary');
              header('Content-Length: '.filesize($file));  // provide file size
              header('Connection: close');
              readfile($file);    // push it out
              exit();
          }
      

      【讨论】:

      • 同样的事情在这里。视频文件正在下载以及使用 quicktime pro player 播放。
      • 请将内容类型更改为'octet/stream''binary' 并尝试。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-30
      • 1970-01-01
      • 2014-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多