/** * Upload file in folder from source destination. * * @param string $folder absolute path to destination folder * @param string $filenameSource source file path * @param string $filenameDest destnation file name * @param boolean $copy use copy function instead upload, default false * @return string relative path of an uploaded file */ public static function uploadFile($folder, $filenameSource, $filenameDest, $copy = false, $reindex = true) { $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication */ $model = JModelLegacy::getInstance(JOOMDOC_DOCUMENT, JOOMDOC_MODEL_PREFIX); /* @var $model JoomDOCModelDocument */ $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $table = JTable::getInstance(JOOMDOC_FILE, JOOMDOC_TABLE_PREFIX); /* @var $table JoomDOCTableFile */ $absolutePath = JPath::clean(dirname($folder . DIRECTORY_SEPARATOR . $filenameDest) . DIRECTORY_SEPARATOR . JoomDOCString::safe(JFile::getName($filenameDest))); $table->path = JoomDOCFileSystem::getRelativePath($absolutePath); if (JFile::exists($absolutePath) && !JoomDOCAccessFileSystem::uploadFile(null, $table->path)) { // control access to reupload old file $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_UNABLE_REUPLOAD_FILE', $table->path), 'notice'); return false; } if (!JoomDOCAccessFileSystem::uploadFile(false, JoomDOCFileSystem::getRelativePath($folder))) { // control access to upload new file $mainframe->enqueueMessage(JText::_('JOOMDOC_UNABLE_UPLOAD'), 'notice'); return false; } $upload = $copy ? JFile::copy($filenameSource, $absolutePath) : JFile::upload($filenameSource, $absolutePath); if ($upload) { $table->store(false, $reindex); } return $upload ? $table->path : false; }