I have a text file containing a sample CSV format, I want my users to be able to download this file from the link.
This file is located in this folder:
assets-> csv-> Sample-CSV-Format.txt
This is the code I've tried so far:
<?php $file_name = "Sample-CSV-Format.txt"; // extracting the extension: $ext = substr($file_name, strpos($file_name,'.') + 1); header('Content-disposition: attachment; filename=' . $file_name); if (strtolower($ext) == "txt") { // works for txt only header('Content-type: text/plain'); } else { // works for all header('Content-type: application/' . $ext);extensions except txt } readfile($decrypted_file_path); ?> <p class="text-center">Download the Sample file <a href="<?php echo base_url();?>assets/csv/Sample-CSV-Format.txt">HERE</a> It has a sample of one entry</p>
This code loads the file when the page loads, instead of the link. It also loads the entire structure of the html page. I want only the text that I wrote in the text file.
Indicate where the problem is?
source share