function force_download ($data, $name, $mimetype, $filesize=false) { // File size not set? if ($filesize == false OR !is_numeric($filesize)) { $filesize = strlen($data); } // Mimetype not set? if (empty($mimetype)) { $mimetype = 'application/octet-stream'; } // Make sure there's not anything else left ob_clean_all(); // Start sending headers 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-Transfer-Encoding: binary"); header("Content-Type: " . $mimetype); header("Content-Length: " . $filesize); header("Content-Disposition: attachment; filename=\"" . $name . "\";" ); // Send data echo $data; die(); }
function force_download($filename, $mimetype = '') { $filenameOrig = $filename; # $filename = str_replace(,PATH_site,$filename); $filename = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . $filename; #if (!file_exists($filename)) return false; // Mimetype not set? if (empty($mimetype)) { $file_extension = strtolower(substr(strrchr($filename, "."), 1)); switch ($file_extension) { case "pdf": $mimetype = "application/pdf"; break; case "exe": $mimetype = "application/octet-stream"; break; case "zip": $mimetype = "application/zip"; break; case "doc": $mimetype = "application/msword"; break; case "xls": $mimetype = "application/vnd.ms-excel"; break; case "ppt": $mimetype = "application/vnd.ms-powerpoint"; break; case "gif": $mimetype = "image/gif"; break; case "png": $mimetype = "image/png"; break; case "jpeg": case "jpg": $mimetype = "image/jpg"; break; default: $mimetype = "application/force-download"; } } // Make sure there's nothing else left ob_clean_all(); // Start sending headers 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-Transfer-Encoding: binary'); header('Content-Type: ' . 'image/jpg'); header('Content-Disposition: attachment; filename="' . basename($filename) . '";'); // Send data readfile($filename); exit; }
{ $ob_active = ob_get_length() !== FALSE; while ($ob_active) { ob_end_clean(); $ob_active = ob_get_length() !== FALSE; } return FALSE; } switch ($file_extension) { case "pdf": $ctype = "application/pdf"; break; case "doc": $ctype = "application/vnd.ms-word"; break; default: $ctype = "application/force-download"; } ob_clean_all(); header("Pragma: public"); header("Expires: 0"); header("Pragma: no-cache"); header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); header("Content-Type: application/download"); header('Content-disposition: attachment; filename=' . basename($upload_file_name)); header("Content-Type: application/{$ctype}"); header('Content-Length: ' . filesize($upload_file_name)); @readfile($upload_file_name); exit(0);