/** * Sends the requested file to the browser * @return string */ public function actionDownload() { //Load filedetails if (validateSystemid($this->getSystemid())) { /** @var $objFile class_module_mediamanager_file */ $objFile = class_objectfactory::getInstance()->getObject($this->getSystemid()); //Succeeded? if ($objFile instanceof class_module_mediamanager_file && $objFile->getIntRecordStatus() == "1" && $objFile->getIntType() == class_module_mediamanager_file::$INT_TYPE_FILE) { //Check rights if ($objFile->rightRight2()) { //Log the download class_module_mediamanager_logbook::generateDlLog($objFile); //Send the data to the browser $strBrowser = getServer("HTTP_USER_AGENT"); //Check the current browsertype if (uniStrpos($strBrowser, "IE") !== false) { //Internet Explorer class_response_object::getInstance()->addHeader("Content-type: application/x-ms-download"); class_response_object::getInstance()->addHeader("Content-type: x-type/subtype\n"); class_response_object::getInstance()->addHeader("Content-type: application/force-download"); class_response_object::getInstance()->addHeader("Content-Disposition: attachment; filename=" . preg_replace('/\\./', '%2e', saveUrlEncode(trim(basename($objFile->getStrFilename()))), substr_count(basename($objFile->getStrFilename()), '.') - 1)); } else { //Good: another browser vendor class_response_object::getInstance()->addHeader("Content-Type: application/octet-stream"); class_response_object::getInstance()->addHeader("Content-Disposition: attachment; filename=" . saveUrlEncode(trim(basename($objFile->getStrFilename())))); } //Common headers class_response_object::getInstance()->addHeader("Expires: Mon, 01 Jan 1995 00:00:00 GMT"); class_response_object::getInstance()->addHeader("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); class_response_object::getInstance()->addHeader("Pragma: no-cache"); class_response_object::getInstance()->addHeader("Content-description: JustThum-Generated Data\n"); class_response_object::getInstance()->addHeader("Content-Length: " . filesize(_realpath_ . $objFile->getStrFilename())); //End Session $this->objSession->sessionClose(); class_response_object::getInstance()->sendHeaders(); //Loop the file $ptrFile = @fopen(_realpath_ . $objFile->getStrFilename(), 'rb'); fpassthru($ptrFile); @fclose($ptrFile); ob_flush(); flush(); return ""; } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_FORBIDDEN); } } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_NOT_FOUND); } } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_NOT_FOUND); } //if we reach up here, something gone wrong :/ class_response_object::getInstance()->setStrRedirectUrl(str_replace(array("_indexpath_", "&"), array(_indexpath_, "&"), class_link::getLinkPortalHref(class_module_system_setting::getConfigValue("_pages_errorpage_")))); class_response_object::getInstance()->sendHeaders(); class_response_object::getInstance()->sendContent(); return ""; }
rawIncludeError("global exception handler"); } //register global exception handler for exceptions thrown but not catched (bad style ;) ) @set_exception_handler(array("class_exception", "globalExceptionHandler")); //Include the logging-engine if (!@(include_once _corepath_ . "/module_system/system/class_logger.php")) { rawIncludeError("logging engine"); } //---The Path on web------------------------------------------------------------------------------------- require_once _corepath_ . "/module_system/system/class_config.php"; $strHeaderName = class_config::readPlainConfigsFromFilesystem("https_header"); $strHeaderValue = strtolower(class_config::readPlainConfigsFromFilesystem("https_header_value")); if (strpos($_SERVER['SCRIPT_FILENAME'], "/debug/")) { //Determine the current path on the web $strWeb = dirname((isset($_SERVER[$strHeaderName]) && strtolower($_SERVER[$strHeaderName]) == $strHeaderValue ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']); define("_webpath_", saveUrlEncode(substr_replace($strWeb, "", strrpos($strWeb, "/")))); } else { //Determine the current path on the web $strWeb = dirname((isset($_SERVER[$strHeaderName]) && strtolower($_SERVER[$strHeaderName]) == $strHeaderValue ? "https://" : "http://") . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : "localhost") . $_SERVER['SCRIPT_NAME']); define("_webpath_", saveUrlEncode($strWeb)); } //---Include Section 2----------------------------------------------------------------------------------- //load module-ids bootstrapIncludeModuleIds(); //---Auto-Loader for classes----------------------------------------------------------------------------- require_once _corepath_ . "/module_system/system/class_classloader.php"; spl_autoload_register(array(class_classloader::getInstance(), "loadClass")); //The Carrier-Class if (!@(include_once _corepath_ . "/module_system/system/class_carrier.php")) { rawIncludeError("carrier-class"); }
/** * Writes the current array of data to the given csv-file or directly to the browser. * Make sure to have set all needed values before, otherwise * an exception is thrown * * @return bool * * @param bool $bitStreamToBrowser * @param bool $bitExcludeHeaders skip the header-row in the output, generated based on the mapping * * @throws class_exception */ public function writeArrayToFile($bitStreamToBrowser = false, $bitExcludeHeaders = false) { //all needed values set before? if ($this->arrData != null && $this->arrMapping != null && $this->strFilename != null) { //create file-content. use a file-pointer to avoid max-mem-errors $objFilesystem = new class_filesystem(); //open file if ($bitStreamToBrowser) { class_response_object::getInstance()->addHeader('Pragma: private'); class_response_object::getInstance()->addHeader('Cache-control: private, must-revalidate'); class_response_object::getInstance()->setStrResponseType(class_http_responsetypes::STR_TYPE_CSV); class_response_object::getInstance()->addHeader("Content-Disposition: attachment; filename=" . saveUrlEncode(trim(basename($this->strFilename)))); class_response_object::getInstance()->sendHeaders(); } else { $objFilesystem->openFilePointer($this->strFilename); } //the first row should contain the row-names if (!$bitExcludeHeaders) { $strRow = ""; foreach ($this->arrMapping as $strTagetCol) { //add enclosers? if ($this->strTextEncloser != null) { $strTagetCol = $this->strTextEncloser . $strTagetCol . $this->strTextEncloser; } $strRow .= $strTagetCol . $this->strDelimiter; } //remove last delimiter, eol $strRow = uniSubstr($strRow, 0, uniStrlen($this->strDelimiter) * -1); //add a linebreak $strRow .= "\n"; //write header to file if ($bitStreamToBrowser) { echo $strRow; } else { $objFilesystem->writeToFile($strRow); } } //iterate over the data array to write it to the file foreach ($this->arrData as $arrOneRow) { $strRow = ""; foreach ($this->arrMapping as $strSourceCol => $strTargetCol) { if (isset($arrOneRow[$strSourceCol])) { $strEntry = $arrOneRow[$strSourceCol]; //escape the delimiter maybe occuring in the text $strEntry = uniStrReplace($this->strDelimiter, "\\" . $this->strDelimiter, $strEntry); //add enclosers? if ($this->strTextEncloser != null) { $strEntry = $this->strTextEncloser . $strEntry . $this->strTextEncloser; } } else { $strEntry = ""; } $strRow .= $strEntry . $this->strDelimiter; } //remove last delimiter, eol $strRow = uniSubstr($strRow, 0, uniStrlen($this->strDelimiter) * -1); //add linebreak $strRow .= "\n"; //and write to file if ($bitStreamToBrowser) { echo $strRow; } else { $objFilesystem->writeToFile($strRow); } } //and close the filepointer... if (!$bitStreamToBrowser) { $objFilesystem->closeFilePointer(); } if ($bitStreamToBrowser) { flush(); die; } return true; } else { throw new class_exception("can't proceed, needed values missing", class_exception::$level_ERROR); } }