Php 文件下载提供警报消息,而不是下载

Php 文件下载提供警报消息,而不是下载,php,Php,点击按钮,我正在通过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."); $typ

点击按钮,我正在通过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。请先禁用/卸载它,然后您的代码应该可以正常工作。

我通过下面的代码获得了所需的OP。创建了一个隐藏的文本文件下载btn超链接,并在成功后单击它

success: function(data){
   swal("Download List", data, "success");

   //  alert(data);
   $('#getfile')[0].click();
}
这提供了带有文本文件下载的弹出窗口

,您可以检查下载HTML属性,目前大多数浏览器都支持该属性。明显的标题内容类型:文件;不是正确的mime类型