Pogledajte određenu poruku
Staro 21. 03. 2006.   #2
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

Imao sam sličan problem pre nekih 6 meseci. Sad sam već zaboravio u čemu je tačno kvaka, ali evo nađoh funkciju koju sam tada napisao:

PHP kôd:
  /**
  * Force download of specific file
  *
  * @access public
  * @param string $path File path
  * @param string $type Serve file as this type
  * @return void
  */
  
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());
    
  } 
// end func download_file 
Probaj sa ovim pa mi javi kako se snalazi. Tada sam baš ludeo zbog problema i probao razne varijacije tako da je moguće da ova funkcija ima i elemenata viška. U suštini, može da prosledi fajl ili da forsira download...

PS: $force_download bi trebalo da bude TRUE kako bi se fajl prosledio kao attachment ne inline (tj. kako bi pokrenuo download).

Poslednja izmena od Ilija Studen : 21. 03. 2006. u 22:38.
Ilija Studen je offline   Odgovorite uz citat