* @package tao */ class tao_helpers_Export { /** * get the path to save and retrieve the exported files regarding the current extension * @return string the path */ public static function getExportPath() { $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tao_export'; if (!file_exists($path)) { mkdir($path); } return $path; } public static function getRelativPath($file) { return ltrim(substr($file, strlen(self::getExportPath())), DIRECTORY_SEPARATOR); } public static function getExportFile($filename = null) { if (is_null($filename)) { $path = tempnam(self::getExportPath(), 'tao_export_'); } else { $path = self::getExportPath() . DIRECTORY_SEPARATOR . $filename; } return $path; } public static function outputFile($relPath, $filename = null) { $fullpath = self::getExportPath() . DIRECTORY_SEPARATOR . $relPath; if (tao_helpers_File::securityCheck($fullpath, true) && file_exists($fullpath)) { Context::getInstance()->getResponse()->setContentHeader(tao_helpers_File::getMimeType($fullpath)); $fileName = empty($filename) ? basename($fullpath) : $filename; header('Content-Disposition: attachment; fileName="' . $fileName . '"'); header("Content-Length: " . filesize($fullpath)); //Clean all levels of output buffering while (ob_get_level() > 0) { ob_end_clean(); } flush(); $fp = fopen($fullpath, "r"); if ($fp !== false) { while (!feof($fp)) { echo fread($fp, 65536); flush(); } fclose($fp); @unlink($fullpath); } else { common_Logger::e('Unable to open File to export' . $fullpath); } } else { common_Logger::e('Could not find File to export: ' . $fullpath); } } }