Server : Apache System : Linux indy02.toastserver.com 3.10.0-962.3.2.lve1.5.85.el7.x86_64 #1 SMP Thu Apr 18 15:18:36 UTC 2024 x86_64 User : palandch ( 1163) PHP Version : 7.1.33 Disable Function : NONE Directory : /home/palandch/www/core/model/modx/processors/workspace/packages/ |
<?php /** * Upload transport package to Packages directory * * @param string $file The transport package to upload * * @package modx * @subpackage processors.browser.file */ class modBrowserPackageUploadProcessor extends modProcessor { /** @var modMediaSource $source */ public $source; public function checkPermissions() { return $this->modx->hasPermission('file_upload'); } public function getLanguageTopics() { return array('file'); } public function initialize() { if(empty($_FILES)){ return $this->modx->lexicon('no_file_err'); } $this->getSource(); $this->setProperty('files',$_FILES); return true; } public function process() { // Even though we're not using media sources, it seems like the // easiest way to check permissions (and waste time/effort/memory) $this->source->initialize(); if (!$this->source->checkPolicy('create')) { return $this->failure($this->modx->lexicon('permission_denied')); } // Prepare the upload path and check it exists $destination = $this->modx->getOption('core_path').'packages/'; if(!is_dir($destination)) return $this->failure("Packages directory doesnt appear to exist!"); //@TODO Lexiconize // Grab the file $file = array_shift($this->getProperty('files')); // Check MIME type of file if($file['type'] != 'application/zip') return $this->failure("1 This file does not appear to be a transport package"); //@TODO Lexiconize // Check valid name of file if(preg_match("/.+\\.transport\\.zip$/",$file['name'])===false) return $this->failure("2 This file [{$file['name']}] does not appear to be a transport package"); //@TODO Lexiconize // Return response if(move_uploaded_file($file['tmp_name'],$destination.$file['name'])){ return $this->success(); } else { return $this->failure($this->modx->lexicon('unknown_error')); } } /** * Get the active Source * @return modMediaSource|boolean */ public function getSource() { $this->modx->loadClass('sources.modMediaSource'); $this->source = modMediaSource::getDefaultSource($this->modx); if (empty($this->source) || !$this->source->getWorkingContext()) { return false; } return $this->source; } } return 'modBrowserPackageUploadProcessor';