Source of: /manual/en/features.file-upload.multiple.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/features.file-upload.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'features.file-upload.multiple.php',
1 => 'Uploading multiple files',
),
'up' =>
array (
0 => 'features.file-upload.php',
1 => 'Handling file uploads',
),
'prev' =>
array (
0 => 'features.file-upload.common-pitfalls.php',
1 => 'Common Pitfalls',
),
'next' =>
array (
0 => 'features.file-upload.put-method.php',
1 => 'PUT method support',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="features.file-upload.multiple" class="sect1">
<h2 class="title">Uploading multiple files</h2>
<p class="simpara">
Multiple files can be uploaded using different
<i>name</i> for <i>input</i>.
</p>
<p class="simpara">
It is also possible to upload multiple files simultaneously and
have the information organized automatically in arrays for you. To
do so, you need to use the same array submission syntax in the
HTML form as you do with multiple selects and checkboxes:
</p>
<p class="para">
</p><div class="example">
<p><b>Example #1 Uploading multiple files</b></p>
<div class="example-contents programlisting">
<div class="htmlcode"><pre class="htmlcode"><form action="file-upload.php" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" value="Send files" />
</form></pre>
</div>
</div>
</div><p>
</p>
<p class="simpara">
When the above form is submitted, the arrays
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']</a></var>,
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['name']</a></var>, and
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['size']</a></var> will be
initialized (as well as in <var class="varname">$HTTP_POST_FILES</var> for PHP versions prior
to 4.1.0).
When
<a href="ini.core.php#ini.register-globals" class="link">register_globals</a> is on, globals for uploaded
files are also initialized. Each of these will be a numerically
indexed array of the appropriate values for the submitted files.
</p>
<p class="simpara">
For instance, assume that the filenames
<var class="filename">/home/test/review.html</var> and
<var class="filename">/home/test/xwp.out</var> are submitted. In this
case, <var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['name'][0]</a></var>
would contain the value <var class="filename">review.html</var>, and
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['name'][1]</a></var> would
contain the value <var class="filename">xwp.out</var>. Similarly,
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['size'][0]</a></var> would
contain <var class="filename">review.html</var>'s file size, and so forth.
</p>
<p class="simpara">
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['name'][0]</a></var>,
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['tmp_name'][0]</a></var>,
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['size'][0]</a></var>, and
<var class="varname"><a href="reserved.variables.files.php" class="classname">$_FILES['userfile']['type'][0]</a></var> are
also set.
</p>
</div><?php manual_footer(); ?>