您需要在链接指向的页面上编写文件下载代码。从链接中提取文件名并编写以下代码
if (file_exists($file))
{
if (FALSE!== ($handler = fopen($file, 'r')))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: chunked'); //changed to chunked
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
//header('Content-Length: ' . filesize($file)); //Remove
//Send the content in chunks
while(false !== ($chunk = fread($handler,4096)))
{
echo $chunk;
}
}
exit;
}
谢谢。我会试一试 – user1597438
谢谢。这可以创建一个url,但是,当我试图下载文件时,我无法打开它和我的电子邮件的所有其他内容,它们都是文本消失。为什么是这样? – user1597438
你把这段代码放在哪里?在您的电子邮件内容中,您无需更改任何内容。您只需将此代码放在电子邮件中的链接指向的地方 –