summaryrefslogtreecommitdiff
path: root/tmp-upload
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-07-11 17:22:57 +0200
committerPeter Wu <lekensteyn@gmail.com>2013-07-11 17:22:57 +0200
commitbada02eb0781180a75ca02ee6d30bf161dd7e717 (patch)
treec658736b64526acc31d787338cacd575624cf366 /tmp-upload
parenteb5736156bdb736f8197d92fc83b799586ae492e (diff)
downloadscripts-bada02eb0781180a75ca02ee6d30bf161dd7e717.tar.gz
tmp-upload: support multiple file upload
Diffstat (limited to 'tmp-upload')
-rwxr-xr-xtmp-upload20
1 files changed, 17 insertions, 3 deletions
diff --git a/tmp-upload b/tmp-upload
index 3578a50..6aa070c 100755
--- a/tmp-upload
+++ b/tmp-upload
@@ -87,9 +87,22 @@ if (is_dir($path)) {
exit;
}
-$msg = NULL;
-if (isset($_FILES["file"]["name"])) {
+$msg = "";
+if (isset($_FILES["file"]["name"]) && is_array($_FILES["file"]["name"])) {
$upload = $_FILES["file"];
+ for ($i=0; $i<count($_FILES["file"]["name"]); $i++) {
+ $upload = array();
+ foreach ($_FILES["file"] as $key=>$vals) {
+ $upload[$key] = $vals[$i];
+ }
+ $res = saveUpload($upload);
+ if ($res) $msg .= "$res<br>\n";
+ }
+}
+function saveUpload($upload) {
+ global $relDir;
+
+ $msg = NULL;
$name = trim(basename($upload["name"]), ".");
$name = preg_replace('/[\x00-\x1F\x7F]/', '', $name);
if ($relDir === '') {
@@ -114,13 +127,14 @@ if (isset($_FILES["file"]["name"])) {
$msg = "File could not be saved.";
}
}
+ return $msg;
}
?>
<!doctype html>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1">
<form action="/" method="POST" enctype="multipart/form-data">
-<input type="file" name="file">
+<input type="file" name="file[]" multiple>
<input type="submit" value="Upload">
</form>
<?php