php - File download function fails to attach complete file name and extension -
i have function use prompt csv files download. however, filename fails complete in mozilla browser works chrome. instance, if file name should f1_open_marksheet.csv, mozilla prompt download f1 (missing rest of file name , extension. code buggy?
<?php function pushdownloadfile($filename){ header('content-description: file transfer'); header('content-type: text/csv; charset=utf-8'); header('content-disposition: attachment; filename='.$filename); header('content-transfer-encoding: binary'); header('expires: 0'); header('cache-control: must-revalidate'); header('pragma: public'); header('content-length: ' . filesize($filename)); ob_clean(); flush(); readfile($filename); unlink($filename); } ?>
the flaw caused white space in file name eg f 1_open_marksheet.csv replaced hyphen f_1_open_marksheet.csv . credits @cbroe sharing link in comment above.
Comments
Post a Comment