maximum file size file_get_contents


Large files (250mb+) are stored on local filesystem using obsfucated filenames. File meta data (eg original filename) is stored in a database.

A PHP script uses file_get_contents() to force the download of the file to a logged in user, prompting the user to download the file with the original filename.

What is the maximum filesize that can be piped through the php function file_get_contents()?
Who is Participating?
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.


This was taken from

post_max_size         integer                                 Sets max size of post data allowed. This setting also affects         file upload. To upload large files, this value must be larger         than upload_max_filesize.                         If memory limit is enabled by your configure script, memory_limit also affects         file uploading. Generally speaking,         memory_limit should be         larger than post_max_size .                 When an integer is used, the  value is measured in bytes. Shorthand notation, as described  in this FAQ, may also be used.                   If the size of post data is greater than post_max_size, the         $_POST and $_FILES         superglobals         are empty. This can be tracked in various ways, e.g. by passing the         $_GET variable to the script processing the data,         i.e. <form action="edit.php?processed=1">,         and then checking if $_GET['processed'] is set.                
Note:                      PHP allows shortcuts for bit values, including K (kilo), M (mega)            and G (giga). PHP will do the conversions automatically if you            use any of these. Be careful not to exceed the 32 bit signed integer            limit (if you're using 32bit versions) as it will cause your script            to fail.          
Another usefull bit of information
Beverley PortlockCommented:
Something else to bear in mind is that there was a 32bit integer problem with some PHP file handling which limits files to 2GB in size. I wouldn't recommend uploading them, but if you are manipulating them on disc bear it in mind.

IIRC the problem was fixed in PHP5.1 or 5.2
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Ray PaseurCommented:
There may also be limits imposed by your hosting service on memory utilization.  file_get_contents() will try to load the entire file into memory, and this may trip the lever.  Best to ask your host about that.  A workaround is to process the file incrementally, using record functions such as fgets() or fread().

Good luck, ~Ray

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
cfpdevAuthor Commented:

I'm not talking about POST/file uploads. Thanks for the info anyway.


Files won't be more than hundreds of megabytes.


You're not wrong re file_get_contents and memory handling. This seems a pretty good solution using fread:

My initial tests on vmware seem pretty favourable using this method. While not as good as a straight link to the file using apache, it's a lot less memory intensive than file_get_contents.
cfpdevAuthor Commented:
cheers ray.
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.