cant get values printed in to a file
Posted
by
user1371896
on Stack Overflow
See other posts from Stack Overflow
or by user1371896
Published on 2012-07-09T02:54:08Z
Indexed on
2012/07/09
3:15 UTC
Read the original article
Hit count: 155
Iam trying to pass the value stored in the variable fieldCSV to file data.csv...Ive used javascript and php to do this.. I have triggered an ajax request when a value is stored in to the variable fieldCSV, bt this is nt working as the file that gets downloaded prints the php error inside it instead of csv..
$.ajax({
type: "POST",
url: "/test/fileDownload.php",
data: {
name: fieldCSV},
});
<?php
$name = $_POST["name"];
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen('php://output', 'w');
fputcsv($output, $name);
?>
What am I doing wrong?
© Stack Overflow or respective owner