I am forcing a file to download. It is an xml file. The problem is that when I am downloading it, the file contains the html dump of the current page from which the download was started.Here is the snippet
File:/bitrix/modules/export/admin/export.php
$name='market'.date('Y-m-d-H-i-s').'.yml';
$file='/bitrix/modules/export/export/'.$name;
$filename=$_SERVER["DOCUMENT_ROOT"].$file;
$fp=fopen($filename,"wb");
/*
*
* Here goes some generating script
*
*/
fclose($fp);
header('Content-disposition:attachment;filename="'.$name.'"');
header('Content-type: application/svg+xml');
readfile(realpath($file));
It is hard to get the download script to work when it contains blank lines, different code, etc. Posting the filename after the file is generated should work. Download script example:
Hope this helps.