Jump to content

Recommended Posts

Hello ,

 

I am trying to enable my php script to work for download accelerator.Facing following problems

 

1:When i download a file by using Download Accelerator ,I am receiving corrupted file only.

 

2.Same code is working in the case of Gwget 0.96,

 

The following code i got when i searched, but i find that too not working.

 

 

<?php

$file="./notes.zip";

dl_file_resume($file);

 

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', $filename, substr_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;

}

?>

 

 

 

According to my assumption i am having problem in fseek($fp,$range);

 

 

 

Could you please help me, How can i enable my php script to work for download accelerator

Thanks

Link to comment
https://forums.phpfreaks.com/topic/84978-resume-downloading-php/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.