kunal
kunal

Reputation: 1

How to allow downloading a file of 1GB

I want to allow the user to download a file up to 1GB in size, but according to my code only a file of 113MB can be downloaded...

header('Content-type: application/zip');

//open/save dialog box
header('Content-Disposition: attachment; filename="check.zip"');

//read from server and write to buffer
readfile('check.zip');

Can anyone tell me how to download a larger file?

Upvotes: 0

Views: 972

Answers (3)

kongaraju
kongaraju

Reputation: 9596

Increase your file write buffer chunk size to maximum of file. That will decrease the utilization of resources and your download works fine.

Edit:

Use HTML5 webworkers to download large. Webworkers works in background so you can able to download large files.

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

I'm going to guess from what you've said that you're getting an "out of memory" error.

In that case, perhaps this note from the documentation might be of interest:

Note:

readfile() will not present any memory issues, even when sending large files, on its own. If you encounter an out of memory error ensure that output buffering is off with ob_get_level().

So, check ob_get_level() and call ob_end_flush() if necessary to stop output buffering.


Alternatively, you could do something like this:

$f = fopen("check.zip","rb");
while(!feof($f)) {
    echo fgets($f);
    flush();
}

Another option is this:

header("Location: check.zip");

This will redirect the browser to the check.zip file. Since it's a download, the existing page won't be affected. You can even output the rest of a page to say something like "Your download will begin momentarily" to the user.

Upvotes: 4

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798536

Either read and echo the file a chunk at a time, or use something like mod_sendfile to make it Not Your Problem.

Upvotes: 0

Related Questions