'PHP Download JSON and CSV file from local directory
I aim to download the news.json file in a PHP website from my computer file directory. When click on a button, it calls the downloadFile.php to force download the file from my computer. The codes work for downloading other files like images and docs except json and csv files. Is there any way to download the mentioned file types or my code has some problem.
$file = ("C:\Users\THINKPAD\Downloads\my_file_name.png");
$filetype=filetype($file);
$filename=basename($file);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
