What must be done to make codeigniter force_download to download large files?

Hi Experts!

I'm facing problems when trying to download a 267Mb file by using Codeigniter's force_download.

When downloading smaller files, no problems.
After a long time, the name of the file to be downloaded appears but without the size and after download
it the file has  0KB.

After download:
The code I used:
      $data = file_get_contents(base_url('arquivos/cesans/e_pub/' . $arquivo));
       force_download($arquivo, $data);

Open in new window

Thanks in advance!
Eduardo FuerteDeveloper and AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
You are probably just running out of memory.  The code you show above reads the entire file into memory before it does the force_download.  If you can increase the amount of memory available, you may be able to download larger files.
Eduardo FuerteDeveloper and AnalystAuthor Commented:
Hello Dave

I did it before...
The directive in PHP.ini I changed was:

; Resource Limits ;

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 512M

Open in new window

It was 128M before and causes a memory error.
Maybe it's still insuficient, I'm going to increase it to 1024M

Am I in the right way?  Another directive must be changed too?

The file has 267M.
Dave BaldwinFixer of ProblemsCommented:
That looks ok to me but I never download files that large.  Another thing you may run into is that the script may timeout before the download is done.  267MB takes a while to download.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Eduardo FuerteDeveloper and AnalystAuthor Commented:
After tests  1024M make it run OK!
Eduardo FuerteDeveloper and AnalystAuthor Commented:
In fact is an eBook !  The others are much smaller  treating agro subjects...but this is about the 100 better experimental receipts developed in our experimental kitchen...rsrsrs
Loganathan NatarajanLAMP DeveloperCommented:
Also check these variable whether you have set enough memory to process.
max_execution_time & post_max_size
Eduardo FuerteDeveloper and AnalystAuthor Commented:
Thanks for the assistance!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.