Last active
August 29, 2015 14:05
-
-
Save Kcko/f9d0e0551d5ec2436ffd to your computer and use it in GitHub Desktop.
Download třída - pro starší projekty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* trida pro stazeni souboru | |
* tato trida umoznuje stejnou funkcnost jak v IE tak ve firefoxu | |
* | |
* @author Dostal Ales | |
* @version 1.1 | |
* @date 13.4.2006 | |
* | |
*/ | |
class DownloadFile | |
{ | |
/****************************** METODY TRIDY ******************************/ | |
/** | |
* konstruktor tridy pro stazeni souboru | |
* | |
* @param String $file zdroj k souboru, ktery se bude stahovat | |
* | |
*/ | |
function ExecuteDL($file) | |
{ | |
// zjisteni, zda soubor existuje | |
if (!is_file($file)) { | |
die("<b>404 Soubor neexistuje!</b>"); | |
} | |
// ziskani informaci o souboru | |
$len = filesize($file); | |
$filename = basename($file); | |
$file_extension = strtolower(substr(strrchr($filename,"."),1)); | |
// nastaveni content-type pro vybrane soubory | |
switch( $file_extension ) | |
{ | |
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; | |
case "mp3": $ctype="audio/mpeg"; break; | |
case "wav": $ctype="audio/x-wav"; break; | |
case "mpeg": | |
case "mpg": | |
case "mpe": $ctype="video/mpeg"; break; | |
case "mov": $ctype="video/quicktime"; break; | |
case "avi": $ctype="video/x-msvideo"; break; | |
# tyto soubory nemohou byt stazeny | |
case "php": | |
case "htm": | |
case "html": | |
case "txt": die("<b>Není možné stahovat ". $file_extension ." soubory!</b>"); | |
break; | |
default: $ctype="application/force-download"; | |
} | |
# odeslani hlavicek | |
session_cache_limiter("private"); # v IE nelze stáhnout dokument pres HTTPS | |
header("Pragma: public"); | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
header("Cache-Control: public"); | |
header("Content-Description: File Transfer"); | |
# generuje typ pro content-type | |
header("Content-Type: $ctype"); | |
# co stahuji | |
$header="Content-Disposition: attachment; filename=".str_replace("./download/", "", $file).";"; | |
header($header ); | |
header("Content-Transfer-Encoding: binary"); | |
header("Content-Length: ".$len); | |
readfile($file); | |
exit; | |
} # public function __construct($file) | |
} # class APIDownloadFile | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment