创建下载链接,音乐或视频 [英] Create download link for music or video
问题描述
我有视频和音频文件,HTML文件。我如MP3或MP4使用标签的href和下载文件要链接文件。我的视频和音频文件保存在同一文件夹中与我的HTML文件。
i have html file with video and audio file. and i want to links file such as mp3 or mp4 using tag a href and download that file. My video and audio file stored in same folder with my html file.
我已经试过这code:
i have tried this code :
<a href="music/hermin.mp3" target="_blank">download</a>
但不能下载我的文件,只需打开一个新的标签,在中央戏剧暂停控制。
but not downloaded my file, just open a new tab with a play pause controls in the center.
此<一个href=\"http://stackoverflow.com/questions/2793751/how-can-i-create-download-link-in-html\">question我到下载添加到我的href标记,但它是现代的浏览器。怎么样在旧的浏览器?
from this question i get to add "download" to my href tag, but it is for modern browser. How about for old browser?
我怎么可以创建HTML文件,并支持所有浏览器(不仅为现代浏览器)?
how i can create a download link for my video/audio in html file and support for all browser (not only for modern browser)?
在此先感谢和抱歉,我的英语不好。
thanks in advance and sorry for my bad English.
推荐答案
这取决于你的浏览器设置和插件但是如果你正在使用PHP,你可以做一个脚本下载像这样的文件:
It depends of your browser settings and plugins however if you are using php you can do a script to download the file like this one:
<?php
if (isset($_GET['file'])) {
$file = $_GET['file'] ;
if (file_exists($file) && is_readable($file) && preg_match('/\.mp3$/',$file)) {
header('Content-type: application/mp3');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
}
} else {
header("HTTP/1.0 404 Not Found");
echo "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>";
}
?>
另存为的download.php
save it as download.php
然后建立这样一个链接
<html>
<body>
<a href="download.php?file=test.mp3">download</a>
</body>
</html>
现在应该工作,有一个美好的一天。
It should work now, have a nice day.
这篇关于创建下载链接,音乐或视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!