note 73444 deleted from features.file-upload.multiple by peehaa
| From: | peehaa@php.net | Date: | Mon, 04 Nov 2013 09:14:50 +0000 |
| Subject: | note 73444 deleted from features.file-upload.multiple by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197429@lists.php.net to get a copy of this message | ||
Note Submitter: captlid at yahoo dot com
----
I noticed that the manual does not have a basic processing script for testing purposes to process
multiple file uploads. It took me about an hour to figure this out so I figured it should help some
newbie.
Also on windows, the OS does not care if you use backslashes and front slashes while writing up a
directory path. So for compatibility with *nix just keep it as a foward slash.
(Tested with php5, php4, apache 1.3x and 2x, on winxp pro, win2k pro and win98se and freebsd.)
The script is kept simple for illustration purposes. Dont use it in a production environment.
The form
<form method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<?
for($i = 1; $i <= $_POST[totalfiles]; $i++) { echo $i.'. <input type="file"
name="photos[]"><br>'."\n"; }
?>
<input type="submit" name="sendfiles" value="Send
Files"></form>
The processing script, for simplicities sake in the same file.
if ($_POST[sendfiles]) {
print_r($_POST); echo '<pre>'; print_r($_FILES); echo '</pre>';
$uploaddir = getcwd().'/photos/; //a directory inside
foreach ($_FILES[photos][name] as $key => $value) {
$uploadfile = $uploaddir . basename($_FILES[photos][name][$key]);
//echo $uploadfile;
if (move_uploaded_file($_FILES['photos']['tmp_name'][$key], $uploadfile)) { echo
$value . ' uploaded<br>'; }
}
}