/** * @module org.rhaco.Flow * @param mixed $obj */ public function flow_exception_output($obj, \Exception $exception) { \org\rhaco\Log::disable_display(); \org\rhaco\net\http\Header::send('Content-Type', $this->mode == 'jsonp' ? 'text/javascript' : 'application/json'); $error = array('error' => array()); if ($exception instanceof \org\rhaco\Exceptions) { foreach (\org\rhaco\Exceptions::gets() as $g => $e) { $error['error'][] = array('message' => $e->getMessage(), 'group' => $g, 'type' => basename(str_replace("\\", '/', get_class($e)))); } } else { $error['error'][] = array('message' => $exception->getMessage(), 'group' => 'exceptions', 'type' => basename(str_replace("\\", '/', get_class($exception)))); } $json = \org\rhaco\lang\Json::encode($error); print $this->mode == 'jsonp' ? $this->varname . '(' . $json . ')' : $json; }
private static function output_file_content($filename, $disposition) { if ($filename instanceof \org\rhaco\io\File) { if (is_file($filename->fullname())) { $filename = $filename->fullname(); } else { \org\rhaco\net\http\Header::send('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT'); \org\rhaco\net\http\Header::send('Content-Type', $filename->mime() . '; name=' . $filename->name()); \org\rhaco\net\http\Header::send('Content-Disposition', $disposition . '; filename=' . $filename->name()); print $filename->value(); exit; } } if (is_file($filename)) { $update = @filemtime($filename); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $update <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { \org\rhaco\net\http\Header::send_status(304); exit; } \org\rhaco\net\http\Header::send('Last-Modified', gmdate('D, d M Y H:i:s', $update) . ' GMT'); \org\rhaco\net\http\Header::send('Content-Type', self::mime($filename) . '; name=' . basename($filename)); \org\rhaco\net\http\Header::send('Content-Disposition', $disposition . '; filename=' . basename($filename)); if (isset($_SERVER['HTTP_RANGE']) && preg_match("/^bytes=(\\d+)\\-(\\d+)\$/", $_SERVER['HTTP_RANGE'], $range)) { list($null, $offset, $end) = $range; $length = $end - $offset + 1; \org\rhaco\net\http\Header::send_status(206); \org\rhaco\net\http\Header::send('Accept-Ranges', 'bytes'); \org\rhaco\net\http\Header::send('Content-length', sprint('%u', $length)); \org\rhaco\net\http\Header::send('Content-Range', sprintf('bytes %u-%u/%u', $offset, $end, filesize($filename))); print file_get_contents($filename, null, null, $offset, $length); exit; } else { \org\rhaco\net\http\Header::send('Content-length', sprintf('%u', filesize($filename))); $fp = fopen($filename, 'rb'); while (!feof($fp)) { echo fread($fp, 8192); flush(); } fclose($fp); exit; } } \org\rhaco\net\http\Header::send_status(404); exit; }