2

I have a function that I use to prompt CSV files for download. However, the filename fails to complete in Mozilla browser but works well with Chrome. For instance, if the file name should be F1_Open_marksheet.csv, Mozilla will prompt the download as F1 (missing the rest of the file name and extension. Could it be that my code is 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);
}
?>
  • your function is missing closing brackets `}` – Ahmed Khan Aug 24 '16 at 08:41
  • 1
    Possible duplicate of [How to encode the filename parameter of Content-Disposition header in HTTP?](http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http) – CBroe Aug 24 '16 at 09:09

1 Answers1

0

The flaw was caused by a white space in the file name eg F 1_Open_marksheet.csv which I replaced with a hyphen to F_1_Open_marksheet.csv . Credits to @CBroe for sharing a link in a comment above.