Mutley Posted January 21, 2009 Share Posted January 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141764-solved-file-extension-not-shown-on-downloads/ Share on other sites More sharing options...
MadTechie Posted January 21, 2009 Share Posted January 21, 2009 does the downloaded file have the extension .xls ? if so then its a problem on the client (downloaders) PC ie office not installed Quote Link to comment https://forums.phpfreaks.com/topic/141764-solved-file-extension-not-shown-on-downloads/#findComment-742097 Share on other sites More sharing options...
Mutley Posted January 21, 2009 Author Share Posted January 21, 2009 There is no extension. Which is odd, as PDF/PSD works fine. Office is installed on the machine. Quote Link to comment https://forums.phpfreaks.com/topic/141764-solved-file-extension-not-shown-on-downloads/#findComment-742100 Share on other sites More sharing options...
MadTechie Posted January 21, 2009 Share Posted January 21, 2009 in that case your need to check where your getting $file from as its $file = "spreadsheet"; not $file = "spreadsheet.xls"; Quote Link to comment https://forums.phpfreaks.com/topic/141764-solved-file-extension-not-shown-on-downloads/#findComment-742103 Share on other sites More sharing options...
Mutley Posted January 21, 2009 Author Share Posted January 21, 2009 It echos the extension. It says on the Save As popup: application/octet-stream As I said, it picks up the .PSD or .PDF file extensions fine. Quote Link to comment https://forums.phpfreaks.com/topic/141764-solved-file-extension-not-shown-on-downloads/#findComment-742110 Share on other sites More sharing options...
MadTechie Posted January 21, 2009 Share Posted January 21, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/141764-solved-file-extension-not-shown-on-downloads/#findComment-742132 Share on other sites More sharing options...
Mutley Posted January 21, 2009 Author Share Posted January 21, 2009 Thanks alot! That worked! Do you know why? Quote Link to comment https://forums.phpfreaks.com/topic/141764-solved-file-extension-not-shown-on-downloads/#findComment-742162 Share on other sites More sharing options...
MadTechie Posted January 21, 2009 Share Posted January 21, 2009 Add the quotes to the file time, may of worked but by telling the browser the Content-Type should work Quote Link to comment https://forums.phpfreaks.com/topic/141764-solved-file-extension-not-shown-on-downloads/#findComment-742173 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.