PHP强力下载帮助 [英] PHP Force Download Help

查看:136
本文介绍了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屋!

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