From 7619fd09a9dfe25c4a6517c9c443725fc60240f2 Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Sat, 2 Jun 2012 23:18:29 +0200 Subject: [PATCH] adding basic upload and unzip functionality --- .../components/com_jedchecker/controller.php | 15 +++++ .../com_jedchecker/controllers/uploads.php | 67 +++++++++++++++++++ .../components/com_jedchecker/jedchecker.php | 19 ++++-- .../views/uploads/tmpl/default.php | 26 +++++++ .../views/uploads/view.html.php | 24 +++++++ 5 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 source/administrator/components/com_jedchecker/controller.php create mode 100644 source/administrator/components/com_jedchecker/controllers/uploads.php create mode 100644 source/administrator/components/com_jedchecker/views/uploads/tmpl/default.php create mode 100644 source/administrator/components/com_jedchecker/views/uploads/view.html.php diff --git a/source/administrator/components/com_jedchecker/controller.php b/source/administrator/components/com_jedchecker/controller.php new file mode 100644 index 0000000..99512b4 --- /dev/null +++ b/source/administrator/components/com_jedchecker/controller.php @@ -0,0 +1,15 @@ +path = JPATH_COMPONENT_ADMINISTRATOR . '/tmp/'; + parent::__construct(); + } + + /** + * basic upload + * @return bool + */ + public function upload() { + $file = JRequest::getVar('extension', '', 'files', 'array'); + if($file['tmp_name']) { + $path = JPATH_COMPONENT_ADMINISTRATOR . '/tmp/'; + $filepath = $path . strtolower($file['name']); +// let us remove all previous uplaods + $folders = JFolder::folders($path); + foreach($folders as $folder) { + JFolder::delete($folder); + } + + $object_file = new JObject($file); + $object_file->filepath = $filepath; + $file = (array) $object_file; + +// let us try to upload + if (!JFile::upload($file['tmp_name'], $file['filepath'])) + { + // Error in upload + JError::raiseWarning(100, JText::_('COM_JEDCHECKER_ERROR_UNABLE_TO_UPLOAD_FILE')); + return false; + } + + return true; + } + + return false; + } + + /** + * unzip the file + * @return bool + */ + public function unzip() { + + $file = JFolder::files($this->path); + + $result = JArchive::extract($this->path.$file[0], $this->path); + + return $result; + } +} diff --git a/source/administrator/components/com_jedchecker/jedchecker.php b/source/administrator/components/com_jedchecker/jedchecker.php index aac684c..c8d8181 100644 --- a/source/administrator/components/com_jedchecker/jedchecker.php +++ b/source/administrator/components/com_jedchecker/jedchecker.php @@ -1,8 +1,15 @@ execute(JRequest::getCmd('task')); +$controller->redirect(); \ No newline at end of file diff --git a/source/administrator/components/com_jedchecker/views/uploads/tmpl/default.php b/source/administrator/components/com_jedchecker/views/uploads/tmpl/default.php new file mode 100644 index 0000000..3097c01 --- /dev/null +++ b/source/administrator/components/com_jedchecker/views/uploads/tmpl/default.php @@ -0,0 +1,26 @@ + +
+ + + + + +
\ No newline at end of file diff --git a/source/administrator/components/com_jedchecker/views/uploads/view.html.php b/source/administrator/components/com_jedchecker/views/uploads/view.html.php new file mode 100644 index 0000000..316bfc9 --- /dev/null +++ b/source/administrator/components/com_jedchecker/views/uploads/view.html.php @@ -0,0 +1,24 @@ +setToolbar(); + parent::display($tpl); + } + + public function setToolbar() { + JToolBarHelper::custom('uploads.unzip', 'unzip', 'unzip', 'unzip', false); + } +} \ No newline at end of file