summaryrefslogtreecommitdiffstats
path: root/system/libraries/Upload.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-02-25 11:23:34 +0100
committerAndrey Andreev <narf@devilix.net>2014-02-25 11:23:34 +0100
commite7d017bcc38909f55e8f817b27263e59d1ca5598 (patch)
tree85836e47a34cac921e5302b68b989e41dd4a1ab2 /system/libraries/Upload.php
parent3a9f325cdff1fda2f2b37498a689ac2cde058195 (diff)
Add array notation support for file field names in CI_Upload
Requested in #1691
Diffstat (limited to 'system/libraries/Upload.php')
-rw-r--r--system/libraries/Upload.php35
1 files changed, 28 insertions, 7 deletions
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 66514cd69..583a97693 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -363,7 +363,28 @@ class CI_Upload {
public function do_upload($field = 'userfile')
{
// Is $_FILES[$field] set? If not, no reason to continue.
- if ( ! isset($_FILES[$field]))
+ if (isset($_FILES[$field]))
+ {
+ $_file = $_FILES[$field];
+ }
+ // Does the field name contain array notation?
+ elseif (($c = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $field, $matches)) > 1)
+ {
+ $_file = $_FILES;
+ for ($i = 0; $i < $c; $i++)
+ {
+ // We can't track numeric iterations, only full field names are accepted
+ if (($field = trim($matches[0][$i], '[]')) === '' OR ! isset($_file[$field]))
+ {
+ $_file = NULL;
+ break;
+ }
+
+ $_file = $_file[$field];
+ }
+ }
+
+ if ( ! isset($_file))
{
$this->set_error('upload_no_file_selected');
return FALSE;
@@ -377,9 +398,9 @@ class CI_Upload {
}
// Was the file able to be uploaded? If not, determine the reason why.
- if ( ! is_uploaded_file($_FILES[$field]['tmp_name']))
+ if ( ! is_uploaded_file($_file['tmp_name']))
{
- $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error'];
+ $error = isset($_file['error']) ? $_file['error'] : 4;
switch ($error)
{
@@ -413,18 +434,18 @@ class CI_Upload {
}
// Set the uploaded data as class variables
- $this->file_temp = $_FILES[$field]['tmp_name'];
- $this->file_size = $_FILES[$field]['size'];
+ $this->file_temp = $_file['tmp_name'];
+ $this->file_size = $_file['size'];
// Skip MIME type detection?
if ($this->detect_mime !== FALSE)
{
- $this->_file_mime_type($_FILES[$field]);
+ $this->_file_mime_type($_file);
}
$this->file_type = preg_replace('/^(.+?);.*$/', '\\1', $this->file_type);
$this->file_type = strtolower(trim(stripslashes($this->file_type), '"'));
- $this->file_name = $this->_prep_filename($_FILES[$field]['name']);
+ $this->file_name = $this->_prep_filename($_file['name']);
$this->file_ext = $this->get_extension($this->file_name);
$this->client_name = $this->file_name;