我有download.php
文件:
$file = // path to file
if ( file_exists($file) ) {
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename=myfile.csv');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
因此,如果打开http://mysite.com/download.php
,csv
则下载文件。
我想通过电子邮件发送这个网址,为此我这样做:
$to = // recipient
$title = // msg title
$download_url = 'http://mysite.com/download.php';
$msg = 'some text <a href="'.$download_url.'" target="_self">download file</a>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
mail($to, $title, $msg, $headers);
我的问题是:当单击“下载文件”链接(在电子邮件中)时,会在浏览器中打开另一个窗口。
问题:有可能不打开另一个,但保持相同的窗口,然后下载文件?