public function testGetFolderPath() { // We first get the base path $base = filemanager_helpers_FileUtils::getBasePath(); $filePath = $base . 'Animals/puss-in-boots.png'; $folderPath = filemanager_helpers_FileUtils::getFolderPath($filePath); $this->assertEquals($folderPath, '/Animals/'); // It does not exist! $filePath = $base . 'Animals/hippo-in-boots.png'; $folderPath = filemanager_helpers_FileUtils::getFolderPath($filePath); $this->assertNull($folderPath); $base = 'C:\\wamp3\\www\\taotrunk\\filemanager\\views\\data\\'; $filePath = $base . 'Animals/chicken.png'; $folderPath = filemanager_helpers_FileUtils::getFolderPath($filePath, $base, false); $this->assertEquals($folderPath, '/Animals/'); // Test a linux like test. $base = '/var/www/taoinstall/filemanager/views/data/'; $filePath = $base . 'Animals/puss-in-boots.png'; $folderPath = filemanager_helpers_FileUtils::getFolderPath($filePath, $base, false); $this->assertEquals($folderPath, '/Animals/'); $filePath = $base . 'puss-in-boots.png'; $folderPath = filemanager_helpers_FileUtils::getFolderPath($filePath, $base, false); $this->assertEquals($folderPath, '/'); }
<?php /** * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); * * */ $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'localData.zip'; filemanager_helpers_FileUtils::import($file);
/** * @return tao_models_classes_fsAccess_AccessProvider */ private static function getAccessProvider() { if (is_null(self::$provider)) { $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('filemanager'); self::$provider = tao_models_classes_fsAccess_Manager::singleton()->getProvider($ext->getConfig(self::CONFIG_KEY_CONTROLLER)); } return self::$provider; }
<?php /** * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); * * */ $extension = common_ext_ExtensionsManager::singleton()->getExtensionById('filemanager'); $dataPath = $extension->getDir() . 'views' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR; $dataUrl = $extension->getConstant('BASE_WWW') . 'data/'; tao_helpers_File::emptyDirectory($dataPath); $fileSystem = tao_models_classes_FileSourceService::singleton()->addLocalSource('Filemanager Directory', $dataPath); $provider = tao_models_classes_fsAccess_DirectAccessProvider::spawnProvider($fileSystem, $dataUrl); filemanager_helpers_FileUtils::setAccessProvider($provider);
/** * delete the selected file or folder * * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} */ public function delete() { $data = array('deleted' => false); if ($this->hasRequestParameter('file')) { $file = urldecode($this->getRequestParameter('file')); if (tao_helpers_File::securityCheck($file, true)) { $data['deleted'] = unlink(filemanager_helpers_FileUtils::cleanConcat(array(filemanager_helpers_FileUtils::getBasePath(), $file))); } } if ($this->hasRequestParameter("folder")) { $folder = urldecode($this->getRequestParameter('folder')); if (tao_helpers_File::securityCheck($folder, true)) { if (filemanager_helpers_FileUtils::deleteFolder(filemanager_helpers_FileUtils::cleanConcat(array(filemanager_helpers_FileUtils::getBasePath(), $folder)), true)) { $data['deleted'] = true; } } } echo json_encode($data); }