Pogledajte određenu poruku
Staro 21. 05. 2006.   #3
Ilija Studen
Direktor Kombinata
Invented the damn thing
 
Avatar Ilija Studen
 
Datum učlanjenja: 07.06.2005
Poruke: 2.669
Hvala: 44
119 "Hvala" u 64 poruka
Ilija Studen će postati "faca" uskoroIlija Studen će postati "faca" uskoro
Default

Frankenštajn funkcija:

PHP kôd:
/**
* Forward specific file to the browser. Download can be forced (dispolition: attachment) or passed as inline file
*
* @param string $path File path
* @param string $type Serve file as this type
* @param string $name If set use this name, else use filename (basename($path))
* @param boolean $force_download Force download (add Disposition => attachement)
* @return boolean
*/
function download_file($path$type 'application/octet-stream'$name ''$force_download false) {
  
  
// Check file...
  
if (!is_file($path) || connection_status()!=0) return false;
  
  
// headers...
  
if($force_download) {
    
header("Cache-Control: public");
    
//session_cache_limiter("must-revalidate");
  
} else {
    
header("Cache-Control: no-store, no-cache, must-revalidate");
    
header("Cache-Control: post-check=0, pre-check=0"false);
    
header("Pragma: no-cache");
  } 
// if
  
header("Expires: ".gmdate("D, d M Y H:i:s"mktime(date("H")+2date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
  
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
  
header("Content-Type: $type");
  
header("Content-Length: ".(string)(filesize($path)));
  
  
// Prepare disposition
  
$disposition $force_download 'attachment' 'inline';
  
  
// Name...
  
if(trim($name) == '') {
    
header("Content-Disposition: $disposition; filename=\"" basename($path)) . "\"";
  } else {
    
header("Content-Disposition: $disposition; filename=\"" trim($name)) . "\"";
  } 
// if
  
header("Content-Transfer-Encoding: binary\n");
  
  if (
$file fopen($path'rb')) {
    while(!
feof($file) and (connection_status()==0)) {
      print(
fread($file1024*8));
      
flush();
    } 
// while
    
fclose($file);
  } 
// if
  
  // Done...
  
return((connection_status() == 0) && !connection_aborted());
  
// download_file 
Ilija Studen je offline   Odgovorite uz citat