note 73444 added to features.file-upload.multiple
| From: | captlid at yahoo dot com | Date: | Fri, 23 Feb 2007 14:08:17 +0000 |
| Subject: | note 73444 added to features.file-upload.multiple | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123767@lists.php.net to get a copy of this message | ||
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>'; }
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 71.247.95.114
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.multiple.php
Edit -- https://master.php.net/note/edit/73444
Del: integrated -- https://master.php.net/note/delete/73444/integrated
Del: useless -- https://master.php.net/note/delete/73444/useless
Del: bad code -- https://master.php.net/note/delete/73444/bad+code
Del: spam -- https://master.php.net/note/delete/73444/spam
Del: non-english -- https://master.php.net/note/delete/73444/non-english
Del: in docs -- https://master.php.net/note/delete/73444/in+docs
Del: other reasons-- https://master.php.net/note/delete/73444
Reject -- https://master.php.net/note/reject/73444
Search -- https://master.php.net/manage/user-notes.php