PHP强力下载帮助 [英] PHP Force Download Help
本文介绍了PHP强力下载帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php
函数下载()
{
$ fullpath = $ _SERVER ['DOCUMENT_ROOT']。front.dwg; //文件的完整路径
$ filename =front.dwg; //文件文件nmae
$ mm_type =application / octet-stream;
header(Cache-Control:public,must-revalidate);
header(Pragma:hack);
header(Content-Type:$ mm_type);
header(Content-Length:。(string)(filesize($ fullpath)));
header('Content-Disposition:attachment; filename ='。$ filename。'');
header(Content-Transfer-Encoding:binary\\\
);
}
?>
< html>
< body>
< a href =#onclick =<?php Download()?>>测试< / a>
< / body>
< / html>
解决方案
你需要拉出你的功能并保存它作为download.php
然后只需要一个链接:
< a href =download.php>
Download.php应如下所示:
$ fullpath = $ _SERVER ['DOCUMENT_ROOT']。front.dwg; //文件的完整路径
$ filename =front.dwg; //文件文件nmae
$ mm_type =application / octet-stream;
header(Cache-Control:public,must-revalidate);
header(Pragma:hack);
header(Content-Type:$ mm_type);
header(Content-Length:。(string)(filesize($ fullpath)));
header('Content-Disposition:attachment; filename ='。$ filename。'');
header(Content-Transfer-Encoding:binary\\\
);
I've been wrestling around with this for awhile now. I am trying to make it so when a user click a link it will force a download. Here's my code so far:
<?php
function Download()
{
$fullpath = $_SERVER['DOCUMENT_ROOT']."front.dwg"; //Full path of document
$filename = "front.dwg"; //Document file nmae
$mm_type="application/octet-stream";
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($fullpath)) );
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary\n");
}
?>
<html>
<body>
<a href="#" onclick="<?php Download() ?>">Test</a>
</body>
</html>
解决方案
Your going to need to pull out your function and save it as "download.php"
Then just have a link that goes to it:
<a href="download.php">
Download.php should look like this:
$fullpath = $_SERVER['DOCUMENT_ROOT']."front.dwg"; //Full path of document
$filename = "front.dwg"; //Document file nmae
$mm_type="application/octet-stream";
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($fullpath)) );
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary\n");
这篇关于PHP强力下载帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文