单击下载按钮时,应在后端下载

时间:2013-10-11 09:53:29

标签: javascript php html ajax

我有一个下载按钮..下载按钮下载应该在后端发生,我应该继续做其他任务..当我点击其他按钮时,下载不应该打破..有一种方式在PHP处理这个..如果是的话可以用什么方法 我试过卷曲功能

<?
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://localhost:8888/test/download_ipad.php');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);

curl_exec($ch);
curl_close($ch);
?>

但不是下载而是打印整个文件

1 个答案:

答案 0 :(得分:0)

创建一个新的php文件,并在按钮href标签中提供指向该文件的链接。

在php文件中,您需要为pdf和文件路径设置标题,例如:

<?php 
     $filename = "filepath";
//header for the file type
header('Content-type: audio/mp3');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Length: " . filesize($filename));
readfile($filename);

&GT;