public static function enablePropelLogging() { $logger = Logging::getLogger(); Propel::setLogger($logger); $con = Propel::getConnection(); $con->useDebug(true); $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT); $config->setParameter('debugpdo.logging.details.method.enabled', true); $config->setParameter('debugpdo.logging.details.time.enabled', true); $config->setParameter('debugpdo.logging.details.mem.enabled', true); }
/** * Allows remote client to download requested media file. * * @return void * */ public function getMediaAction() { global $CC_CONFIG; // disable the view and the layout $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $api_key = $this->_getParam('api_key'); $download = "true" == $this->_getParam('download'); $logger = Logging::getLogger(); if (!in_array($api_key, $CC_CONFIG["apiKey"]) && is_null(Zend_Auth::getInstance()->getStorage()->read())) { header('HTTP/1.0 401 Unauthorized'); print 'You are not allowed to access this resource.'; $logger->info("401 Unauthorized"); return; } $filename = $this->_getParam("file"); $file_id = substr($filename, 0, strpos($filename, ".")); if (ctype_alnum($file_id) && strlen($file_id) == 32) { $media = StoredFile::RecallByGunid($file_id); if ($media != null && !PEAR::isError($media)) { $filepath = $media->getFilePath(); if (is_file($filepath)) { // possibly use fileinfo module here in the future. // http://www.php.net/manual/en/book.fileinfo.php $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext == "ogg") { header("Content-Type: audio/ogg"); } else { if ($ext == "mp3") { header("Content-Type: audio/mpeg"); } } if ($download) { //path_info breaks up a file path into seperate pieces of informaiton. //We just want the basename which is the file name with the path //information stripped away. We are using Content-Disposition to specify //to the browser what name the file should be saved as. // // By james.moon: // I'm removing pathinfo() since it strips away UTF-8 characters. // Using manualy parsing $full_path = $media->getPropelOrm()->getDbFilepath(); $file_base_name = strrchr($full_path, '/'); $file_base_name = substr($file_base_name, 1); header('Content-Disposition: attachment; filename="' . $file_base_name . '"'); } header("Content-Length: " . filesize($filepath)); // !! binary mode !! $fp = fopen($filepath, 'rb'); //We can have multiple levels of output buffering. Need to //keep looping until all have been disabled!!! //http://www.php.net/manual/en/function.ob-end-flush.php while (@ob_end_flush()) { } fpassthru($fp); fclose($fp); //make sure to exit here so that no other output is sent. exit; } else { $logger->err('Resource in database, but not in storage: "' . $filepath . '"'); } } else { $logger->err('$media != null && !PEAR::isError($media)'); } } else { $logger->err('ctype_alnum($file_id) && strlen($file_id) == 32'); } header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); $logger->info("404 Not Found"); return; }