From dbf4512ce48c04af4a8332cff3064f29b5690446 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 27 Apr 2016 20:41:35 -0400 Subject: Revert "Add function Form::saveUploadedFile()" This reverts commit 3d493fc75dc6e3593001c2d9dfef26f4c1d79c2c. The way I was wanting to handle file uploads isn't going to fly with a semantic of PHP and POST var mgmt. -.- Rolling back relevant changes to write up something else. --- app/class/form.class.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'app') diff --git a/app/class/form.class.php b/app/class/form.class.php index 3f28a36..529c480 100644 --- a/app/class/form.class.php +++ b/app/class/form.class.php @@ -232,14 +232,6 @@ class Form /* return */ return count($this->errorlist) == 0; } - - /* - * Save file uploaded through web form - */ - function saveUploadedFile($file, $filename) - { - return move_uploaded_file($file['tmp_name'], $filename); - } } ?> -- cgit v1.2.3 From caebcb442985496b3bddaa3e7c1a752832e32e0b Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 27 Apr 2016 20:43:35 -0400 Subject: Revert "Update function Form::populate() to initialize fields added with Form::field_file()" This reverts commit 1f8b53e426b8c0a1546e9d5c21573be9003cb556. See parent commit message. --- app/class/form.class.php | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'app') diff --git a/app/class/form.class.php b/app/class/form.class.php index 529c480..e748afc 100644 --- a/app/class/form.class.php +++ b/app/class/form.class.php @@ -105,7 +105,7 @@ class Form /* * Populate the form with input data from web page */ - function populate($input, $files = null) + function populate($input) { /* detect duplicate names */ $names = array(); @@ -115,8 +115,6 @@ class Form $names[] = $fld['name']; foreach ($this->enumFields as $fld) $names[] = $fld['name']; - foreach ($this->fileFields as $fld) - $names[] = $fld['name']; if (count(array_unique($names)) != count($names)) { @@ -197,38 +195,6 @@ class Form $this->logError($fld['name'] . " is required"); } - /* init file fields */ - foreach ($this->fileFields as $fld) - { - if (!is_null($files) && isset($files[$fld['name']])) - { - $file = $files[$fld['name']]; - - if ($file['error'] > 0) - { - $this->logError("An unknown error occurred"); - continue; - } - - if ($file['size'] > $fld['maxsize']) - { - $this->logError("File must be no larger than " . $fld['maxsize'] . " bytes"); - continue; - } - - if (is_array($fld['mime']) && array_search($file['type'], $fld['mime']) === false) - { - $this->logError("File type is not supported"); - continue; - } - - $this->$fld['name'] = $file; - } - - else if ($fld['req']) - $this->logError($fld['name'] . " is required"); - } - /* return */ return count($this->errorlist) == 0; } -- cgit v1.2.3 From 9458874e8c194b1c5a53bd3e85f9ba7548c9dac4 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 27 Apr 2016 20:47:21 -0400 Subject: Revert "Add form field type 'file'" This reverts commit 8ad6e8f9223bd3ee214478b3e1247f9c7d8e91ec. See parent commit message --- app/class/form.class.php | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'app') diff --git a/app/class/form.class.php b/app/class/form.class.php index e748afc..9f103ba 100644 --- a/app/class/form.class.php +++ b/app/class/form.class.php @@ -13,7 +13,6 @@ class Form $this->textFields = array(); $this->numbFields = array(); $this->enumFields = array(); - $this->fileFields = array(); $this->errorlist = array(); } @@ -86,22 +85,6 @@ class Form $this->field_enum($name, array("1", "0"), "0"); } - /* - * Add new file field to the form - */ - function field_file($name, $maxsize, $allowed_mime = null, $req = false) - { - if ($req !== true) - $req = false; - - $this->fileFields[] = array( - 'name' => $name, - 'maxsize' => $maxsize, - 'mime' => $allowed_mime, - 'req' => $req - ); - } - /* * Populate the form with input data from web page */ -- cgit v1.2.3 From db369507f636f9395604a5cd72fcfe5d99f97166 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 27 Apr 2016 22:11:58 -0400 Subject: Add function Form::saveFile() This is a rework of how the framework handles performing file uploads. Rather than attaching new fields to a form (of type file) and handling them during populate() then saving later, users can call what is essentially a static function and save files in isolation. Since each webform I can conceive using in Scrott at this time won't be uploading more than one file at a time, this model should work nicely moving forward; however can be easily adjusted if need be. --- app/class/form.class.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'app') diff --git a/app/class/form.class.php b/app/class/form.class.php index 9f103ba..907c0a2 100644 --- a/app/class/form.class.php +++ b/app/class/form.class.php @@ -181,6 +181,47 @@ class Form /* return */ return count($this->errorlist) == 0; } + + /* + * Handle an uploaded file + */ + function saveFile($file, $maxsize, $allowed_mime, $path, $req = false) + { + if (isset($file) && !is_null($file)) + { + if ($file['error'] > 0) + { + $this->logError("An unknown error occurred"); + return false; + } + + if ($file['size'] > $maxsize) + { + $this->logError("File must be no larger than " . $maxsize . " bytes"); + return false; + } + + if (is_array($allowed_mime) && array_search($file['type'], $allowed_mime) === false) + { + $this->logError("File type is not supported"); + return false; + } + + if (!move_uploaded_file($file['tmp_name'], $path)) + { + $this->logError("Error saving uploaded file"); + return false; + } + } + + else if ($req) + { + $this->logError("File upload is required"); + return false; + } + + return true; + } } ?> -- cgit v1.2.3