[Lazarus] How to show a picture in a CGI app?

silvioprog silvioprog at gmail.com
Sat Apr 2 18:46:47 CEST 2011


YES! :}D

This code (from "C:\lazarus\components\fpweb\demo\image") works for me:

[code]
var
  OFN, FN: string;
  F: TFileStream;
begin
  Handled := True;
  OFN := 'C:\lazarus\images\actions\arrow_down.png';
  FN := OFN;
  if (FN = '') then
    raise Exception.Create('This script requires a file name argument');
  // Strip any directory path.
  FN := ExtractFileName(FN);
  // Make sure it is a PNG file.
  FN := ChangeFileExt(FN, '.png');
  FN := IncludeTrailingPathDelimiter(ImageDir) + FN;
  if not FileExistsUTF8(FN) then
    raise Exception.Create('The requested file "' + OFN +
      '" does not exist in the image directory');
  AResponse.ContentType := 'image/png';
  F := TFileStream.Create(UTF8ToSys(FN), fmOpenRead);
  try
    AResponse.ContentStream := F;
    AResponse.SendContent;
    Handled := True;
  finally
    F.Free;
  end;
end;
[/code]

To use:

http://localhost/cgi-bin/imagedemo.cgi/file

The result is a picture without link, perfect to antispam generators.

Please, sorry for my ignorance. ^^

Thx to all!

-- 
Silvio Clécio
=============================================
Blog - silvioprog.com.br
Twitter - twitter.com/silvioprog
LazSolutions - code.google.com/p/lazsolutions
Lazarus-BR - groups.google.com.br/group/lazarus-br?hl=pt-BR
=============================================




More information about the Lazarus mailing list