Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5323
  • Last Modified:

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()?
0
cfpdev
Asked:
cfpdev
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now