Using the following code, files greater than 10Megs do not download. Less than 10 is working. Can anyone explain why? Files that will be downloaded are 5G plus in size. -
function download() {
-
-
global $_GET;
-
-
//Gather relevent info about file
-
$file = "/user/dac420/tts/incoming/".$_GET['name'];
-
$len = filesize($file);
-
$filename = basename($file);
-
$file_extension = strtolower(substr(strrchr($filename,"."),1));
-
-
// Determine correct MIME type
-
switch($file_extension){
-
-
case "asf": $ctype = "video/x-ms-asf"; break;
-
case "avi": $ctype = "video/x-msvideo"; break;
-
case "exe": $ctype = "application/octet-stream"; break;
-
case "mov": $ctype = "video/quicktime"; break;
-
case "mp3": $ctype = "audio/mpeg"; break;
-
case "mpg": $ctype = "video/mpeg"; break;
-
case "mpeg": $ctype = "video/mpeg"; break;
-
case "rar": $ctype = "encoding/x-compress"; break;
-
case "txt": $ctype = "text/plain"; break;
-
case "wav": $ctype = "audio/wav"; break;
-
case "wma": $ctype = "audio/x-ms-wma"; break;
-
case "wmv": $ctype = "video/x-ms-wmv"; break;
-
case "zip": $ctype = "application/x-zip-compressed"; break;
-
default: $ctype = "application/force-download"; break;
-
-
}
-
-
//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,filesize($file)));
-
flush();
-
ob_flush();
-
-
}
-
-
fclose($fp);
-
exit;
-
-
}
-
6 1661
Hi,
Did you set any limit to the file size in the form you use to upload the files?
The solution is to split the file into chunks when sending. Thanks to everyone for your suggestions.
replace the while() in my above code. - //start buffered download
-
while(!feof($fp)){
-
-
$total = filesize($file);
-
$sent = 0;
-
$blocksize = (2 << 20); //2M chunks
-
$handle = fopen($file, "r");
-
-
// Now we need to loop through the file and echo out chunks of file data
-
// Dumping the whole file fails at > 30M!
-
while($sent < $total){
-
echo fread($handle, $blocksize);
-
$sent += $blocksize;
-
}
-
-
exit(0);
-
@flush();
-
@ob_flush();
-
}
-
So now that I have the download working I need to know why the page is not refreshing at the end of the script. The download happen, then nothing. How do i get the page to continue after download?
So now that I have the download working I need to know why the page is not refreshing at the end of the script. The download happen, then nothing. How do i get the page to continue after download?
Hi,
What you can do is send the user to the correct page using header.
Good luck
Nothing greatly important here but, you don't need to globalise GET as it is already a SUPERGLOBAL.
Is that correct?
Hi,
What you can do is send the user to the correct page using header.
Good luck
header() is not working after the feof() call
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jatin |
last post by:
Hey Guys
I have a web application that allows users to download files. But the files
are not hosted on the webserver. The files are stored on external servers and
are referenced by a URL/URI....
|
by: gjzusenet |
last post by:
Hello.
Though Python supports threading, I think it is limited to python code
- as soon as you issue a command that uses an external (C?) module, all
of your python threads hang until this command...
|
by: Richie Kernagan |
last post by:
Howdy
Problem with the fread() call on MS Visual Studio 2005 running under Win 64.
The parameters to fread size and count are both size_t ie 64 bits. Even
so the call fails when the size arg...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |