Pogledajte određenu poruku
Staro 15. 01. 2006.   #1
Bojan Zivanovic
profesionalac
Professional
 
Avatar Bojan Zivanovic
 
Datum učlanjenja: 06.06.2005
Lokacija: Pančevo - Pariz
Poruke: 287
Hvala: 6
8 "Hvala" u 8 poruka
Bojan Zivanovic is on a distinguished road
Pošaljite poruku preko Skype™ za Bojan Zivanovic
Default Download skripta

Zahtevi su bili:
1) Ogranicenje brzine downloada
2) Rad sa akceleratorima, resume support
download.php, ovde se salju headeri, i poziva funkcija za download
EDIT: Ok, akcelerator radi, al nece resume, tj krene on, predje par kilobajta (5 npr) i stane, kao gotovo..
PHP kôd:

$mimes 
mimeTypes('/home/share/public_html/mimes');
$ext explode(".",$file);

foreach(
$ext as $val){
    
$ekstenzija $val;
}
$ext strtolower($ekstenzija);
// use them ($ext is the extension of your file)
if (isset($mimes[$ext])) {
    
$type $mimes[$ext];
}
else {
       
$type 'application/force-download';
}
                        
$size filesize("uploads/$id"."-".$file);  
$seek_start 0// Default values. Will override them latter if the download is partial (resume)
$seek_end $size;

ini_set("zlib.output_compression""Off"); // Some browsers (Opera) corrupt the file if this is on
header("Cache-Control: ");// leave blank to avoid IE errors
header("Pragma: ");// leave blank to avoid IE errors
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // neki dan u proslosti
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Transfer-Encoding: binary");
header("Content-Type: $type");
header("Content-Disposition: attachment; filename=\"$file\"");

    
//  check if http_range is sent by browser (or download manager) . This is used for resuming downloads
    
if (isset($_SERVER['HTTP_RANGE'])) {
        
$seek_range substr($_SERVER['HTTP_RANGE'] , strlen('bytes='));
        
$range explode('-',$seek_range);
        if (
$range[0] > 0) {
            
$seek_start intval($range[0]);
        }
        else {
            
$seek_start 0;
        }
        if (
$range[1] > 0) {
            
$seek_end intval($range[1]);
        }
        else {
            
$seek_end $size-1;
        }
                            
        
header("Content-Length: " . ($seek_end $seek_start 1));            
        
header('Accept-Ranges: bytes');
        
header("HTTP/1.0 206 Partial Content");
        
header("status: 206 Partial Content");
        
header("Content-Range: bytes $seek_start-$seek_end/$size");
        }                         
        else {
            
header("Content-Length: $size");
        } 
E sad sta je fora, ovaj kod gore ne radi nikako, ako izbacim Content-Length header radi bez resume-a.
Al onda nemam velicinu fajla ispisanu, a ne prihvata ni jedan Length (Ukupan, sabran itd...)
Imam osecaj da je on i kriv sto resume ne radi (posto dobro krene, al prerano stane)
Tako da ja tipujem na headere...

Funkciju sam izbacio posto ona sigurno nije uzrok...

P.S. Ako se pitate zasto su komentari englesko-srpski, to je zato sto nije sav kod moj... Ja komentarisem na engleskom (navika od rada sa strancima),a prethodni programer na srpskom...
__________________
The knack of flying is learning how to throw yourself at the ground and miss.

Poslednja izmena od Bojan Zivanovic : 16. 01. 2006. u 02:33.
Bojan Zivanovic je offline   Odgovorite uz citat