0

I have a .TXT file on my xampp server, if a user clicks on a link it should download, but instead it opens up in my browser window.

My code looks as follows:

<a href="<?php echo base_url();?>assets/task/start/<?php echo $files->task_verify_file;?>"><?php echo $files->task_verify_file;?></a>

any one solve the problem thanks

Uraj
  • 47
  • 2
  • 16
  • 1
    Maybe you will find your answer here [how-to-automatically-start-a-download-in-php][1] [1]: http://stackoverflow.com/questions/40943/how-to-automatically-start-a-download-in-php – AdamM Apr 03 '15 at 12:29

1 Answers1

0

I did it like this:

if (file_exists ($file)) {
    header("Content-Type: text/plain; charset=utf-8");
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=".$filename);
    readfile($file);
}
mrh
  • 459
  • 3
  • 7