文件下载提供警告消息,而不是下载它

问题描述 投票:0回答:1

单击按钮时,我正在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);
?>

请帮助。

php
1个回答
-1
投票

我想只是因为您的第三方应用程序(例如IDM)。请先禁用/卸载它,然后您的代码应可以正常运行。

© www.soinside.com 2019 - 2024. All rights reserved.