0
<?php
$name = 't1__'.date('m-d-Y_hia__').$_GET["ident"].'.txt';
$myfile = fopen($name, "w") or die("Unable to open file!");
fwrite($myfile, $_GET["value"]);
fclose($myfile);
?>

Hi! I need help!

So.. I have a file axWrite.php that will get the values from a web-based study I created, but I want to add a download button to get a csv file with the content when I open each file.

For example, from this picture: Picture of the files created from axWrite.php I want to be able to either download when I click the link or when I enter the file I can have a button to download to a csv file inside the page Inside the page with the get values

I have tried:

$filename = $name.".csv";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: text/csv; charset=UTF-16LE");
$out = fopen("php://output",'w');

but it doesnt do anything because it only creates a blank page when i hit on axWrite.php.

Any help would be helpful!

Thanks,

1 Answers1

0

your link or button needs to use your PHP function. Try with that, you can choose between link or button. You can choose between echo + file_get_contents or readfile. I don't remember very well, but the idea is something like this.

/* html - 2 alternatives */ 
<button type="button" onclick="location.href='your-file.php?params=some'">Your text</button>
<a href="your-file.php?params=some">Your text</a>



/* php echo or readfile */
$filename = $name.".csv";
header("Content-Type: text/csv; charset=UTF-16LE");
header("Content-Disposition: attachment;filename=$filename");
echo file_get_contents($filename);
readfile($filename);
exit()
Maxi Schvindt
  • 1,432
  • 1
  • 11
  • 20