Download Files-for most File types
Download Files-for most File types
Function forceDownLoad ($ filename = '', $ data ='') {if ($ filename = ''OR $ data ='') {return false ;} if (FLASE === strpos ($ filename ,'. ') {return false;} $ x = explod ('. ', $ filename); $ extension = end ($ x); $ mimes = array ('hqx' => 'application/mac-binhex40 ', 'cpt' => 'application/mac-compactpro', 'csv' => 'text/x-comma-separated-values ', 'text/csv ', 'application/csv', 'application/excel ', 'application/vnd. msexcel ', 'bi N' => 'application/macbinary ', 'DMs' => 'application/octet-stream', 'lha' => 'application/octet-stream ', 'lzh '=> 'application/octect-stream', 'exe' => array ('application/octet-stream'); if (! Isset ($ mimes [$ extension]) {$ mime = 'application/octet-stream ';} else {$ mime = (is_array ($ mimes [$ extension]);)? $ Mimes [$ extension] [0]: $ mimes [$ extension];} header ('content-type :"'. $ mime. '"'); $ tmpName = $ filename; $ filename = '"''. urlencode ($ tmpName ). "'; // Chinese IE names support if (strtolower ($ _ SERVER ['http _ USER_AGER']), 'Firefox ')! = False) {$ filename = '". $ tmpName. "';} // Firefox supports if (strtolower ($ _ SERVER ['http _ USER_AGER']) and 'chromi' in Chinese ')! = False) {$ filename = '". $ tmpName. "';} // Chrome supports header ('content-Disposition: attachment; filename = '. $ filename); header ('expires: 0'); header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 '); header ('content-Transfer-Encoding: binary '); header ('pragma: no-cache'); header ('content-Length :'. strlen ($ data); exit ($ data );}