jbond Posted April 14, 2008 Share Posted April 14, 2008 Hello everyone, I am having problems with a certain filetype format .msg (which is a format used when saving something as an outlook message format). When this type of file is being retrieved from mysql, a dialog box pops up asking whether to save the the file, type: Unknown File Type. Somehow it doesn't get the message that it needs to be opened by outlook. Following is the piece of code I use to open all sorts of files (excel, word, pdf, gif, jpg, bmp, txt), all of those open without problems using the correct program. header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Content-type: $type"); header("Cache-Control: max-age=60"); Does anyone know if something needs to be added to 'connect' the .msg type of files to the outlook program? Thanks for your assistance Link to comment https://forums.phpfreaks.com/topic/101033-unknown-file-type/ Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 This is local, and not PHP related. You have to set this up via Tools -> Folder Options in windows explorer... or, when you first attempt to open the 'Unknown' file type, it will ask you to choose a program. Choose outlook, then select 'Always use this program...' And you should be fine. Link to comment https://forums.phpfreaks.com/topic/101033-unknown-file-type/#findComment-516678 Share on other sites More sharing options...
jbond Posted April 14, 2008 Author Share Posted April 14, 2008 Discomatt, thanks for the reply. Unfortunately I can't connect this type of extension to the appropriate application because of security issues on our company network that doesn't allow this type of action. I just solved it by inserting following code into the php $query = "SELECT name, type, size, path FROM tbl_details WHERE id='$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $filePath) = mysql_fetch_array($result); $filename = $name; $file_extension = strtolower(substr($filename,strlen($filename)-3,3)); switch ($file_extension) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "msg": $ctype="application/vnd.ms-outlook"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpe": case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: max-age=60, must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: $ctype"); header("Content-Transfer-Encoding: binary"); readfile($filePath); exit; } Using above piece of code starts the outlook application and loads the file correctly. Cheers Gino Link to comment https://forums.phpfreaks.com/topic/101033-unknown-file-type/#findComment-516721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.