$_FILES limited to 20 files?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ColonelSandersLite
Forum Commoner
Posts: 35
Joined: Sun May 09, 2010 1:32 am

$_FILES limited to 20 files?

Post by ColonelSandersLite »

This is something I hadn't seen documented so I thought I would post here to confirm this.

I've been building a file uploader for administrative purposes. I had originally hardcoded a 99 file limit (as an arbitrary "more than you can really use" kind of number, but ran into an issue where php (through $_FILES) does not accept more than 20 files at a time. Since this is an image uploader with optional manual thumbnails, that's effectively 10 images at a time. I suppose I can live with that, but would like to know if anybody knows whether this is due to some obscure setting I can change, a hard limit in php, or something to do with my server setup (currently running PHP5/Apache/Linux).

I thought it might be nice to provide some test code so people with different setups can see what the limit is on their configurations. To that end:

file_limit_test.php

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<?PHP
	$UploadTest_Submit = "";
	import_request_variables("P", "UploadTest_");
	
	if ($UploadTest_Submit == "Submit")
	{
		echo "<pre>";
		print_r($_FILES);
		echo "</pre>";
	} else
	{
		echo "<form action=\"file_limit_test.php\" method=\"post\"  name=\"ImageUpload\"  enctype=\"multipart/form-data\">\n";
		echo "<INPUT type=\"submit\" alt=\"Submit\" name=\"Submit\" value=\"Submit\"><br>\n<br>\n";
		for ($i = 0; $i < 100; $i++)
		{
			echo "<input type=\"file\" name=\"File$i\" alt=\"File Path\" size=\"55\"><br>\n<br>\n";
			echo "<br>\n";
		};
		echo "</form>\n";
	};
?>
		
</body>
</html>

When testing this, you don't need to actually fill out the form as $_FILES will return data even for empty boxes. In other words, just hit submit and view the results.

Results on my end (note only File0 - File19 are returned):
[text]
Array
(
[File0] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File1] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File2] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File3] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File4] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File5] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File6] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File7] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File8] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File9] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File10] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File11] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File12] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File13] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File14] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File15] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File16] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File17] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File18] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

[File19] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)

)

[/text]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: $_FILES limited to 20 files?

Post by Benjamin »

According to the manual, the max_file_uploads php.ini directive has been available since version 5.2.12.

See: http://php.net/manual/en/ini.core.php
User avatar
ColonelSandersLite
Forum Commoner
Posts: 35
Joined: Sun May 09, 2010 1:32 am

Re: $_FILES limited to 20 files?

Post by ColonelSandersLite »

And there it is. Can't blame me for not knowing about something that's only been around a few months ;). I should have known to check the php.ini docs though.

I'm curious though, does anybody know what the limit is on older versions of php? I'd guess 20, since that's what it defaults to currently, but maybe not.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: $_FILES limited to 20 files?

Post by Benjamin »

I would guess that there previously wasn't a limit before this recent addition. I don't know why this was added, but more than likely it was for performance or security concerns.
User avatar
ColonelSandersLite
Forum Commoner
Posts: 35
Joined: Sun May 09, 2010 1:32 am

Re: $_FILES limited to 20 files?

Post by ColonelSandersLite »

From the documentation:

Added "max_file_uploads" INI directive, which can be set to limit the number of file uploads per-request to 20 by default, to prevent possible DOS via temporary file exhaustion.

But yeah, from that sentence no limit makes sense. I'd honestly still like to see someone who has easy access to an old version of php test it though. Hmm... maybe I've still got something running on v4 somewhere...
User avatar
ColonelSandersLite
Forum Commoner
Posts: 35
Joined: Sun May 09, 2010 1:32 am

Re: $_FILES limited to 20 files?

Post by ColonelSandersLite »

Yep, I have something running V4 still :oops:. Tested 100 files and all returned ok. So, limit >= 100.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: $_FILES limited to 20 files?

Post by Benjamin »

I can see how that could take out a server, don't want to say how. Very creative though...
User avatar
ColonelSandersLite
Forum Commoner
Posts: 35
Joined: Sun May 09, 2010 1:32 am

Re: $_FILES limited to 20 files?

Post by ColonelSandersLite »

Check your PMs Benjamin.
Post Reply