Advertisement
Advertisement
| 03.31.2008 at 10:35PM PDT, ID: 23284865 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: |
<? $fileName = 'file1';
$fileExtension = 'pdf';
$sourceFile = $fileName . '.' . $fileExtension;
$outputFile = $sourceFile; // the name they save as can be different to the existing file
// required for IE, otherwise Content-disposition is ignored
//if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');
switch( $fileExtension)
{
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 "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
//session_cache_limiter("");
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=".basename($outputFile).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($sourceFile));
echo 5+6;
echo $fileName; echo $sourceFile;
readfile("$sourceFile") ; // This is the bit that prompts for the download, supress errors for niceness
exit();
?>
|