Forum Moderators: coopster
I've got a problem that ***I think*** has to do with the header encoding for word documents.
The force download function works flawlessly for .pdf, but after I try to open a downloaded word.doc in MS word, I get a "File Conversion" dialog box with "Windows Default", "MS-DOS", and "Other encoding" radio buttons. "Windows Default" is always set when this dialog comes up.
When I press "OK" in this dialog, my document opens - and the body of the document IS there, but it's got a slew of garbage characters before and after the body of the document.
The force download function I'm using is shown below - can anyone see the problem here? Is there a different (updated?) content type that I should be using?
//$filePath already contains both the directory path AND file name
function forceDownload($fileName, $filePath, $fileExt)
{
switch($fileExt)
{
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 "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("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=".$fileName.";" );
header("Content-Transfer-Encoding: binary");
//header("Content-Length: ".$fileSize);
header("Content-Length: ".@filesize($filePath));
@readfile("$filePath") or die("File not found.");
exit();
}
Thanks to all in advance,
Neophyte
I'm not sure what you mean: "Did you have joy with this"?
I haven't found a solution to the .doc encoding problems yet and have had to move on to other aspects of this project just to keep things rolling along.
Do you know why I'm having this problem? Anyone?
I've googled this problem but don't seem to find anyone who has had a similar problem with a .doc file type which makes me, well, a bit concerned.
I've checked and re-checked mime-types in the code already posted and everything seems to be okay there. Could it be that the original .doc file is some how corrupted? Or is the problem originating from MY code? Something missing perhaps?
Neophyte