maximum file size file_get_contents

Scenario:

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()?
cfpdevAsked:
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.

vibrazyCommented:
               Hi,

This was taken from
http://uk.php.net/manual/en/ini.core.php#ini.post-max-size

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.          
0
vibrazyCommented:
Another usefull bit of information

http://drupal.org/node/109994
0
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
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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
0

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:
vibrazy:

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

bportlock:

Files won't be more than hundreds of megabytes.

Ray:

You're not wrong re file_get_contents and memory handling. This seems a pretty good solution using fread:
http://uk.php.net/manual/en/function.fread.php#78406

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.
0
cfpdevAuthor Commented:
cheers ray.
0
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
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.