Mime类型的下载文件 [英] Mime-type of downloading file

查看:122
本文介绍了Mime类型的下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建可下载的视频文件。在我的网站上有一个文件列表。
所有视频都是.flv格式(flash)。有关所有视频文件的确切链接。
但是在点击内容的所有浏览器加载到浏览器的窗口中。我不需要在这里据我了解,我应该创建重定向页面,其中包含mime类型的下载文件。我该怎么办?
语言:php

i'm trying to create downloadable video-files. In my site there is a list of files. All videos are in .flv-format (flash). There is exact link to the file for the all videos. But in all browsers after clicking content is loading to the browser`s window. I needn't in this. As i understand i should create redirect-page wich contains mime-type of the download file. What exactly should i do? Language: php

推荐答案

创建一个包含以下内容的PHP页面:

Create a PHP page with the following:

<?php

$filepath = "path/to/file.ext";

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filepath");
header("Content-Type: mime/type");
header("Content-Transfer-Encoding: binary");
// UPDATE: Add the below line to show file size during download.
header('Content-Length: ' . filesize($filepath));

readfile($filepath);

?>

$ filepath 设置为要下载的文件,并将 Content-Type 设置为正在下载的文件的MIME类型。

Set $filepath to the path of the file to be downloaded, and set Content-Type to the mime type of the file being downloaded.

指向下载链接到此页面。

Point the "download" link to this page.

对于同一类型的多个文件:

For multiple files of the same type:

<?php

$filepath = $_GET['filepath'];

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filepath");
header("Content-Type: mime/type");
header("Content-Transfer-Encoding: binary");
// UPDATE: Add the below line to show file size during download.
header('Content-Length: ' . filesize($filepath));

readfile($filepath);

?>

替换上面指定的信息,并使用GET参数将下载链接指向此页面命名为filepath,其中包含文件路径。

Replace the information as specified above, and point the "download" link to this page with a GET parameter named "filepath" containing the file path.

例如,如果您命名这个php文件download.php,请指定一个名为电影的文件的下载链接。 mov(与download.php相同的目录)为download.php?filepath = movie.mov。

For example, if you name this php file "download.php", point the download link for a file named "movie.mov" (in the same directory as download.php) to "download.php?filepath=movie.mov".

这篇关于Mime类型的下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆