$form->setMaxFileSize(FileSystemTree::getUploadMaxSize() * 1024); $form->addElement('text', 'url_upload', _UPLOADFILEFROMURL, 'class = "inputText"'); $form->addElement('select', 'embed_type', _EMBEDTYPE, array('iframe' => _INLINEIFRAME, 'popup' => _NEWWINDOWPOPUP), 'class = "inputSelect"'); $form->addElement('text', 'popup_parameters', _POPUPPARAMETERS, 'class = "inputText" style = "width:600px"'); $form->addElement('text', 'iframe_parameters', _IFRAMEPARAMETERS, 'class = "inputText" style = "width:600px"'); $form->addElement('submit', 'submit_upload_scorm', _SUBMIT, 'class = "flatButton"'); $form->setDefaults(array('popup_parameters' => 'width=800,height=600,scrollbars=no,resizable=yes,status=yes,toolbar=no,location=no,menubar=no,top="+(parseInt(parseInt(screen.height)/2) - 300)+",left="+(parseInt(parseInt(screen.width)/2) - 400)+"', 'iframe_parameters' => 'height = "100%" width = "100%" frameborder = "no"')); //@todo: url upload, if not exists, report a human-readable error! $timestamp = time(); if ($form->isSubmitted() && $form->validate()) { $values = $form->exportValues(); try { $urlUpload = $form->exportValue('url_upload'); $scormFiles = array(); if ($urlUpload != "") { FileSystemTree::checkFile($urlUpload); $urlArray = explode("/", $urlUpload); $urlFile = preg_replace("/\\?.*/", "", urldecode($urlArray[sizeof($urlArray) - 1])); if (!copy($urlUpload, $currentLesson->getDirectory() . $urlFile)) { $error = error_get_last(); throw new Exception(_PROBLEMUPLOADINGFILE . ': ' . $error['message']); } else { $scormFiles[] = new EfrontFile($currentLesson->getDirectory() . $urlFile); } } else { $filesystem = new FileSystemTree($currentLesson->getDirectory(), true); foreach ($_FILES['scorm_file']['name'] as $key => $value) { if (!in_array($value, $scormFiles)) { //This way we bypass duplicates try { $scormFiles[$value] = $filesystem->uploadFile("scorm_file", $currentLesson->getDirectory(), $key);
FileSystemTree::checkFile($urlUpload); $urlArray = explode("/", $urlUpload); $urlFile = urldecode($urlArray[sizeof($urlArray) - 1]); if (!copy(dirname($urlUpload) . '/' . rawurlencode(basename($urlUpload)), $uploadDir . "/" . $urlFile)) { $errors[] = _PROBLEMUPLOADINGFILE . ': ' . $urlUpload; } else { $uploadedFiles[basename($urlUpload)] = new EfrontFile($uploadDir . "/" . $urlFile); } } } //Perform any path uploads foreach ($values['import_path'] as $key => $pathUpload) { if ($pathUpload && !in_array($pathUpload, $uploadedFiles)) { $pathUpload = EfrontDirectory::normalize($pathUpload); if (strpos(dirname($pathUpload), rtrim(G_ROOTPATH, "/")) !== false) { FileSystemTree::checkFile($pathUpload); $pathArray = explode("/", $pathUpload); $pathFile = urldecode($pathArray[sizeof($pathArray) - 1]); if (!copy($pathUpload, $uploadDir . "/" . $pathFile)) { $errors[] = _PROBLEMUPLOADINGFILE . ': ' . $pathUpload; } else { $uploadedFiles[basename($pathUpload)] = new EfrontFile($uploadDir . "/" . $pathFile); } } else { $errors[] = _PROBLEMUPLOADINGFILE . ': ' . $pathUpload; } } } if (!empty($errors)) { throw new Exception(implode("<br>", $errors)); }
/** * Uncompress file * * This function is used to uncompress the current file. * The uncompressed files will have a database representation, unless $addDb is set to false. * The function supports zip and tar.gz files * <br/>Example: * <code> * $file = new EfrontFile('/var/www/test.zip'); * $uncompressedFiles = $file -> uncompress(); * </code> * * @param boolean $addDB Whether to create a database representation for the extracted files * @return array An array of EfrontFile objects or file paths (depending on wheter a database representation exists) * @since 3.5.0 * @access public */ public function uncompress($addDB = true) { if ($this['extension'] == 'zip') { if ($GLOBALS['configuration']['zip_method'] == 'system') { $blackList = explode(",", $GLOBALS['configuration']['file_black_list']); $blackList[] = 'php'; $blackList[] = 'htaccess'; $blackList = '-x "*.' . implode('" "*.', $blackList) . '"'; if ($GLOBALS['configuration']['file_white_list']) { $whiteList = '"*.' . implode('" "*.', explode(",", $GLOBALS['configuration']['file_white_list'])) . '"'; } else { $whiteList = ''; } if (defined("NO_CHECK_FILE_INTEGRITY") && NO_CHECK_FILE_INTEGRITY) { $blackList = $whiteList = ''; } $response = exec('unzip -qqο "' . $this['path'] . '" ' . $whiteList . ' ' . $blackList . ' -d "' . $this['directory'] . '" 2>&1', $output, $code); if (stripos($response, 'caution') === false && stripos($response, 'warning') === false && $code != 0) { throw new EfrontFileException(_COMMANDFAILEDWITHOUTPUT . ': ' . $response . ". " . _PERHAPSDONTSUPPORTZIP, EfrontFileException::ERROR_ZIP_PROCESSING); } } else { $zip = new ZipArchive(); if ($zip->open($this['path']) === true && $zip->extractTo($this['directory'])) { for ($i = 0; $i < $zip->numFiles; $i++) { $file = $this['directory'] . '/' . $zip->getNameIndex($i); try { //If the file is not allowed, then append to its extension '.ext' FileSystemTree::checkFile($file); } catch (EfrontFileException $e) { $fileObj = new EfrontFile($file); $fileObj->rename($this['directory'] . '/' . $zip->getNameIndex($i) . '.ext', true); $file = $fileObj['path']; } $zipFiles[] = $file; } if ($this['id'] != -1 && $addDB) { $importedFiles = FileSystemTree::importFiles($zipFiles, $options); return $importedFiles; } else { return $zipFiles; } } else { throw new EfrontFileException(_CANNOTOPENCOMPRESSEDFILE . ': ' . $this['path'], EfrontFileException::ERROR_OPEN_ZIP); } } } }