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


when download button is clicked download should happen at backend

我有一个下载程序。单击下载按钮下载应该在后端进行,我应该继续执行其他任务..当我单击其他按钮时,下载不应该中断。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);
?>

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

创建一个新的 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);

?>