Viewed   205 times

I'm using php to download files, rather than the file itself opening in a new window. It seems to work ok for smaller files, but does not work for large files (I need this to work on very large files). Here's the code I have to download the file:

function downloadFile($file) {   
    if (file_exists($file)) {         
        //download file
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: '.filesize($file));

But when I try to download a large file (example 265mb) the browser tells me that it can't find the file? The files are definately on the server, and the script works fine for the smaller files. Is there any way of downloading large files similar to what I already have?



PHP has limits on how long a script can run, and how much memory it can use. It's possible that the script is timing out before it has completed, or is using up too much memory by reading in the large file.

Try tweaking the max_execution_time and memory_limit variables in php.ini. If you don't have access to php.ini, try the set_time_limit and/or ini_set functions.

Tuesday, October 4, 2022

To solve the error : "Internet Explorer cannot download download.php from", Add these headers to your script:

header("Pragma: ");

header("Cache-Control: ");

The code will remove the Cache-Control from headers which makes the download problem.

The above code should be added at the top of the file.

It works fine for us.

Sunday, September 4, 2022

Your update call parameters are reversed. According to your update_book model function the first parameter is the array of data to update, and the second parameter is the where array. However here $this->user_model->update_book(array('book_id' => $this->input->post('book_id')), $data); you have your where first and data second.

It should be:

$this->user_model->update_book($data, array('book_id' => $this->input->post('book_id')));
Monday, August 29, 2022

Are you sure that it's fopen that's failing and not your script's timeout setting? The default is usually around 30 seconds or so, and if your file is taking longer than that to read in, it may be tripping that up.

Another thing to consider may be the memory limit on your script - reading the file into an array may trip over this, so check your error log for memory warnings.

If neither of the above are your problem, you might look into using fgets to read the file in line-by-line, processing as you go.

$handle = fopen("/tmp/uploadfile.txt", "r") or die("Couldn't get handle");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        // Process buffer here..


PHP doesn't seem to throw an error, it just returns false.

Is the path to $rawfile correct relative to where the script is running? Perhaps try setting an absolute path here for the filename.

Friday, December 9, 2022

instead uploading with standard form try uploading with xhr object (as you said) but using file chunk method to send file to server, in this way theorically you should have not upload limits. Try this upload jquery plugin that provides also php scripts: REMOVE BECAUSE CANNOT MANTAIN

New link (free):


Friday, August 5, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :