Thread: Major Additions - DownloadsII
View Single Post
  #2050  
Old 12-10-2007, 11:05 PM
Kingster Kingster is offline
 
Join Date: Jan 2005
Posts: 26
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Kingster View Post
Couple of things that I'm (and my users) are looking for:
Add one more thing to the list - resumable downloads: Some code along these lines:
PHP Code:
<?php
function dl_file_resume($file){

    
//First, see if the file exists
    
if (!is_file($file)) { die("<b>404 File not found!</b>"); }
   
    
//Gather relevent info about file
    
$len filesize($file);
    
$filename basename($file);
    
$file_extension strtolower(substr(strrchr($filename,"."),1));
   
    
//This will set the Content-Type to the appropriate setting for the file
    
switch( $file_extension ) {
        case 
"exe"$ctype="application/octet-stream"; break;
        case 
"zip"$ctype="application/zip"; break;
        case 
"mp3"$ctype="audio/mpeg"; break;
        case 
"mpg":$ctype="video/mpeg"; break;
        case 
"avi"$ctype="video/x-msvideo"; break;
        default: 
$ctype="application/force-download";
    }
   
    
//Begin writing headers
    
header("Cache-Control:");
    
header("Cache-Control: public");
   
    
//Use the switch-generated Content-Type
    
header("Content-Type: $ctype");
    if (
strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
        
# workaround for IE filename bug with multiple periods / multiple dots in filename
        # that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
        
$iefilename preg_replace('/\./''%2e'$filenamesubstr_count($filename'.') - 1);
        
header("Content-Disposition: attachment; filename=\"$iefilename\"");
    } else {
        
header("Content-Disposition: attachment; filename=\"$filename\"");
    }
    
header("Accept-Ranges: bytes");
   
    
$size=filesize($file);
    
//check if http_range is sent by browser (or download manager)
    
if(isset($_SERVER['HTTP_RANGE'])) {
        list(
$a$range)=explode("=",$_SERVER['HTTP_RANGE']);
        
//if yes, download missing part
        
str_replace($range"-"$range);
        
$size2=$size-1;
        
$new_length=$size2-$range;
        
header("HTTP/1.1 206 Partial Content");
        
header("Content-Length: $new_length");
        
header("Content-Range: bytes $range$size2/$size");
    } else {
        
$size2=$size-1;
        
header("Content-Range: bytes 0-$size2/$size");
        
header("Content-Length: ".$size);
    }
    
//open the file
    
$fp=fopen("$file","rb");
    
//seek to start of missing part
    
fseek($fp,$range);
    
//start buffered download
    
while(!feof($fp)){
        
//reset time limit for big files
        
set_time_limit(0);
        print(
fread($fp,1024*8));
        
flush();
        
ob_flush();
    }
    
fclose($fp);
    exit;
}
?>
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01143 seconds
  • Memory Usage 1,811KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete