0

Dublicate error happened in chrome, opera, safari and only works on firefox. Here's the header:

| Header
    | Forcing a download using readfile()
    |----------------
    */

    header('Content-Description: File Transfer');
    header('Content-Type: ' . $file_mime_type);
    header('Content-Disposition: attachment; filename=' . $file);
    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: ' . $file_size);
    ob_clean();
    flush();
    readfile($file_path);
    exit;

I've tried to put double quotes and works but adds to file name - for e.g. -'filename.pdf'

header("Content-Disposition: attachment; filename= . '$file'");

1 Answers1

0

To fix issue you need

// Change this 
header('Content-Disposition: attachment; filename=' . $file);

// To this 
header('Content-Disposition: attachment; filename="'.$file.'"');
Armen
  • 4,064
  • 2
  • 23
  • 40
  • Awesome now works on all browsers.Actually it's this script http://www.tutorialchip.com/php-download-file-script/ I think it's old and for thus have a problem. – ama rullz amarullzz Dec 30 '15 at 09:38
  • How is `Content-Description` the same header as `Content-Disposition`? – Barmar Dec 30 '15 at 09:46
  • Ups :) my bad @Barmar, ok his problem was just with quotas, updating answer – Armen Dec 30 '15 at 09:59
  • @Armen With first line as you said to remove works and without works.Is this a problem to keep first or to remove ? – ama rullz amarullzz Dec 30 '15 at 10:09
  • Tangentially related: if your filename contains special characters, various browsers will need special handling: http://stackoverflow.com/q/93551/1233508 – DCoder Dec 30 '15 at 10:25
  • @amarullzamarullzz no you can keep it, you just need to fix `Content-Disposition` like in updated answer – Armen Dec 30 '15 at 10:37