单击按钮时,我正在AJAX中通过PHP下载文本文件。
这是我的代码。我只收到文件内容的警报,而不下载文件。
<?php
$cpy1 = $_POST['cpy1'];
file_put_contents("download.txt",$cpy1);
$file ="download_link.txt";
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
$type = filetype($file);
// Get a date and timestamp
$today = date("F j, Y, g:i a");
$time = time();
// Send file headers
header("Content-type: $type");
header("Content-Disposition: attachment;filename=download_link.txt");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
// Send the file contents.
set_time_limit(0);
readfile($file);
?>
请帮助。
我想只是因为您的第三方应用程序(例如IDM)。请先禁用/卸载它,然后您的代码应可以正常运行。