|
<%@ WebHandler Language="PHP" Class="Handler" %><?
import namespace System;
import namespace System:::IO;
import namespace System:::Web;
// The class won't expose the needed parameterless constructor if it's not exported.
[Export]
class Handler implements IHttpHandler {
public $IsReusable = true;
function ProcessRequest ($context) {
// Set up the response settings
$context->Response->ContentType = "image/jpeg";
$context->Response->Cache->SetCacheability(HttpCacheability::i'Public');
$context->Response->BufferOutput = false;
$query = $context->Request->QueryString;
$photo_id = $context->Request->QueryString->get_Item("PhotoID");
$album_id = $context->Request->QueryString->get_Item("AlbumID");
$qs_size = $context->Request->QueryString->get_Item("Size");
// Setup the Size Parameter
switch ($qs_size) {
case "S":
$size = PhotoSize::Small;
break;
case "M":
$size = PhotoSize::Medium;
break;
case "L":
$size = PhotoSize::Large;
break;
default:
$size = PhotoSize::Original;
break;
}
// Setup the PhotoID Parameter
$id = -1;
if (isset($photo_id)) {
$id = Convert::ToInt32($photo_id);
$stream = PhotoManager::GetPhoto($id, $size);
} else {
$id = Convert::ToInt32($album_id);
$stream = PhotoManager::GetFirstPhoto($id, $size);
}
// Get the photo from the database, if nothing is returned, get the default "placeholder" photo
if ($stream == NULL) $stream = PhotoManager::GetPhotoPlaceholder($size);
// Write image stream to the response stream
$buffersize = 1024 * 16;
$buffer = System:::Array::CreateInstance(Type::GetType("System.Byte"), $buffersize);
$count = $stream->Read($buffer, 0, $buffersize);
while ($count > 0) {
$context->Response->OutputStream->Write($buffer, 0, $count);
$count = $stream->Read($buffer, 0, $buffersize);
}
}
}
?>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I live in Prague, the capital city of Czech republic (most of the time
). I've been very interested in functional programming recently and I have a passion for the new Microsoft F# language. I'm writing a book about
Functional Programming in the Real World that shows the ideas using examples in C# 3.0 and F#.
I've been Microsoft MVP (for C#) since 2004 and I'm one of the most active members of the F# community. I'm a computer science student at
Charles University of Prague. My hobbies include photography, fractals and of course many things related to computers (except fixing them). My favorite book writers are Terry Pratchett and Philip K Dick and I like paintings by M. C. Escher.
PS: My favorite codeproject icon is .