PHP File Download
$file = "/folder/filename.ext";
function Force_download ($file) {
??? Intercepting file extensions
??? $ext = Explode (".", $file);
??? switch ($ext [sizeof ($ext)-1]) {
??????? Case ' jar ': $mime = "application/java-archive"; Break
??????? Case ' zip ': $mime = "Application/zip"; Break
??????? Case ' jpeg ': $mime = "Image/jpeg"; Break
??????? Case ' jpg ': $mime = "image/jpg"; Break
??????? Case ' jad ': $mime = "Text/vnd.sun.j2me.app-descriptor"; Break
??????? Case "gif": $mime = "Image/gif"; Break
??????? Case "png": $mime = "Image/png"; Break
??????? Case "PDF": $mime = "Application/pdf"; Break
??????? Case "TXT": $mime = "Text/plain"; Break
??????? Case "Doc": $mime = "Application/msword"; Break
??????? Case "ppt": $mime = "Application/vnd.ms-powerpoint"; Break
??????? Case "Wbmp": $mime = "Image/vnd.wap.wbmp"; Break
??????? Case "WMLC": $mime = "APPLICATION/VND.WAP.WMLC"; Break
??????? Case "MP4s": $mime = "Application/mp4"; Break
??????? Case "Ogg": $mime = "Application/ogg"; Break
??????? Case "pls": $mime = "Application/pls+xml"; Break
??????? Case "ASF": $mime = "application/vnd.ms-asf"; Break
??????? Case "swf": $mime = "Application/x-shockwave-flash"; Break
??????? Case "mp4": $mime = "Video/mp4"; Break
??????? Case "M4A": $mime = "Audio/mp4"; Break
??????? Case "M4P": $mime = "Audio/mp4"; Break
??????? Case "MP4A": $mime = "Audio/mp4"; Break
??????? Case "MP3": $mime = "Audio/mpeg"; Break
??????? Case "M3A": $mime = "Audio/mpeg"; Break
??????? Case "M2A": $mime = "Audio/mpeg"; Break
??????? Case "MP2A": $mime = "Audio/mpeg"; Break
??????? Case "MP2": $mime = "Audio/mpeg"; Break
??????? Case "MPGA": $mime = "Audio/mpeg"; Break
??????? Case "wav": $mime = "Audio/wav"; Break
??????? Case "M3U": $mime = "Audio/x-mpegurl"; Break
??????? Case "BMP": $mime = "Image/bmp"; Break
??????? Case "ico": $mime = "Image/x-icon"; Break
??????? Case "3gp": $mime = "VIDEO/3GPP"; Break
??????? Case "3g2": $mime = "VIDEO/3GPP2"; Break
??????? Case "mp4v": $mime = "Video/mp4"; Break
??????? Case "MPG4": $mime = "Video/mp4"; Break
??????? Case "M2V": $mime = "Video/mpeg"; Break
??????? Case "M1V": $mime = "Video/mpeg"; Break
??????? Case "MPE": $mime = "Video/mpeg"; Break
??????? Case "MPEG": $mime = "Video/mpeg"; Break
??????? Case "mpg": $mime = "Video/mpeg"; Break
??????? Case "mov": $mime = "Video/quicktime"; Break
??????? Case "qt": $mime = "Video/quicktime"; Break
??????? Case "avi": $mime = "Video/x-msvideo"; Break
??????? Case "MIDI": $mime = "Audio/midi"; Break
??????? Case "Mid": $mime = "Audio/mid"; Break
??????? Case "AMR": $mime = "AUDIO/AMR"; Break
??????? Default: $mime = "Application/force-download";
??? }
??? Header (' Content-description:file Transfer ');
??? Header (' Content-type: '. $mime);
??? Header (' content-disposition:attachment; Filename= '. basename ($file));
??? Header (' content-transfer-encoding:binary ');
??? Header (' expires:0 ');
??? Header (' Cache-control:must-revalidate, post-check=0, pre-check=0 ');
??? Header (' Pragma:public ');
??? Header (' Content-length: '. FileSize ($file));
??? Ob_clean ();
??? Flush ();
??? ReadFile ($file);
}?