I have an issue. I could not write my array of data into a file using PHP. I am explaining my code below.
<?php
$result=array(array('cat_id'=>'2','cat_name'=>'spirit','subcat_id'=>'20','subcat_name'=>'pizza'),array('cat_id'=>'3','cat_name'=>'Food','subcat_id'=>'23','subcat_name'=>'pakhal'),array('cat_id'=>'2','cat_name'=>'spirit','subcat_id'=>'22','subcat_name'=>'wine'),array('cat_id'=>'2','cat_name'=>'spirit','subcat_id'=>'20','subcat_name'=>'pizza'),array('cat_id'=>'3','cat_name'=>'Food','subcat_id'=>'24','subcat_name'=>'fuddy'),array('cat_id'=>'4','cat_name'=>'Continetal','subcat_id'=>'25','subcat_name'=>'cont'));
$handle = fopen("file.txt", "w");
fwrite($handle, $result);
fclose($handle);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename('file.txt'));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize('file.txt'));
readfile('file.txt');
exit;
?>
Here I need to download also that file. Here I can download the file but this fwrite() expects parameter 2 to be string array given in is written inside that file and no data there. I need to write all of my array of data into that file and download it. Please help me to resolve this issue.
implodefor exampleecho json_encode($result)values.