I have this data that I get from my MySQL table and I've stored it in a variable called $arr. I've json_encoded it into a $json variable:
$arr = array();
while ($blah = mysqli_fetch_assoc(...)) {
$arr[key] = value;
}
$json = json_encode($arr);
The thing that I'm trying to do is to download the contents of just the $json variable into a .json file without saving it on the server. But when I try to do that using
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename='.$file.'');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
echo $json;
(where $file is a generated name for the downloaded file) I get something like this:
<!DOCTYPE html>
<html>
<head>
....
</head>
<body>
<a ...>...</a>{"field":"value","field2":"ИзвеÑтиÑ","field3":"ÐОВ", ...} </body></html>
or the whole .php file content in other words... And as you can see, the encoding is all messed up.
Can you help me identify the problem and possibly give me any ideas on how to fix it.
Any help would be really appreciated : ]