Jump to content

[SOLVED] File extension not shown on downloads


Mutley

Recommended Posts

I use the following to get files off the server as downloads...

 

$file = spreadsheet.xls;

 

It popsup as an Unknown file? It seems with Microsoft Office documents it does this but I've tried PDF and PSD and they display fine and open with the correct application.

 

		header('Content-Description: File Transfer');
	header('Content-Type: application/octet-stream');
	header('Content-Disposition: attachment; filename='.basename($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: ' . filesize($file));
	ob_clean();
	flush();
	readfile($file);
	exit;		

 

Any ideas?

 

Thanks,

Nick.

Try this, if it fails then you could uncomment the 2 commented lines

 

      ini_set('zlib.output_compression','Off'); 
      header('Content-Description: File Transfer');
      header('Content-Type: application/octet-stream');
      header('Content-Disposition: attachment; filename="'.basename($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: ' . filesize($file));
      #header('Content-Type: application/vnd.ms-excel;');
      #header("Content-Type: application/x-msexcel");

      ob_clean();
      flush();
      readfile($file);
      exit;  

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.