【问题标题】:HTML Link for download mp3 support for website and Android Browser用于下载网站和 Android 浏览器的 mp3 支持的 HTML 链接
【发布时间】:2016-02-20 00:36:06
【问题描述】:

我创建了以下链接,但它不支持 Android Chrome 浏览器,所以它不下载歌曲。请提供同样的帮助。

 $path='http://domain.com/admin/'.$_SESSION['video'];

 $file = $path;
<a href="<?php echo $file; ?>" download>Click To Download </a> 

在 Android 浏览器中,点击下载后直接开始播放音频歌曲

【问题讨论】:

  • 你能发布一些代码示例吗?
  • 代码现已更新,视频名称正确来自会话。它在计算机、笔记本电脑浏览器上运行良好,但在 Android 浏览器上运行良好。
  • 你在安卓浏览器中得到了什么?
  • 它直接开始播放音频歌曲一次点击下载
  • 好的,所以你选择了默认播放视频文件的模式,在其他手机上检查我认为它可能在那里下载,你不能用 php 做任何事情

标签: php html hyperlink download


【解决方案1】:

如果你还想强制浏览器下载文件,直接修改HTTP头。这是一个 PHP 代码示例:

    $path = "path/to/video.mp4";
$filename = "video.mp4";
header('Content-Transfer-Encoding: binary');  // For Gecko browsers mainly
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Accept-Ranges: bytes');  // Allow support for download resume
header('Content-Length: ' . filesize($path));  // File size
header('Content-Encoding: none');
header('Content-Type: video/mp4');  // Change the mime type if the file is not PDF
header('Content-Disposition: attachment; filename=' . $filename);  // Make the browser display the Save As dialog
readfile($path);  // This is necessary in order to get it to actually download the file, otherwise it will be 0Kb

请注意,这只是对 HTTP 协议的扩展;一些浏览器可能会忽略它。

【讨论】:

  • 查看此视频使用php强制下载任何文件类型click here (youtube)
  • 视频帮我修复它。非常感谢 Reoxey。
猜你喜欢
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 2018-02-14
  • 2016-06-06
  • 2013-03-06
  • 2011-06-12
  • 2015-06-28
相关资源
最近更新 更多